Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2019-07-22 07:28:38 -0400
committerJuergen Haug2019-07-22 07:28:38 -0400
commit104891dd71c924693d697ab267b6de8166971e6c (patch)
tree8015d670a60bedba41b644f7453ddd36273eb3af
parent4eca3effad21040a922447dbe325b34d25f8502e (diff)
downloadorg.eclipse.etrice-104891dd71c924693d697ab267b6de8166971e6c.tar.gz
org.eclipse.etrice-104891dd71c924693d697ab267b6de8166971e6c.tar.xz
org.eclipse.etrice-104891dd71c924693d697ab267b6de8166971e6c.zip
Bug 549448 - [dialog] reference selection behaves like editor
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/contentassist/FQNLastSegmentFinder.java35
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiModule.java4
-rw-r--r--plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/dialogs/AbstractPropertyDialog.java43
-rw-r--r--plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/dialogs/FilteredContentProposalProvider.java48
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/ActorContainerRefPropertyDialog.java4
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/PortPropertyDialog.java2
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/SPPPropertyDialog.java2
7 files changed, 120 insertions, 18 deletions
diff --git a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/contentassist/FQNLastSegmentFinder.java b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/contentassist/FQNLastSegmentFinder.java
new file mode 100644
index 000000000..b8c165f56
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/contentassist/FQNLastSegmentFinder.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2013 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * CONTRIBUTORS:
+ * Juergen Haug (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.core.common.ui.contentassist;
+
+import org.eclipse.xtext.ui.editor.contentassist.FQNPrefixMatcher.LastSegmentFinder;
+
+/**
+ * Finds last segment of FQN. Used for prefix matching in content proposals.
+ */
+public class FQNLastSegmentFinder implements LastSegmentFinder {
+
+ @Override
+ public String getLastSegment(String fqn, char delimiter) {
+ if (fqn == null || fqn.length() == 0)
+ return null;
+
+ int idx = fqn.lastIndexOf(delimiter);
+ if(idx > 0 && idx < fqn.length() - 2)
+ return fqn.substring(idx + 1);
+ return null;
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiModule.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiModule.java
index d5ac6fe15..06f9aeabb 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiModule.java
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiModule.java
@@ -15,6 +15,7 @@
package org.eclipse.etrice.core.ui;
import org.eclipse.etrice.core.common.ui.autoedit.BaseAutoEditStrategyProvider;
+import org.eclipse.etrice.core.common.ui.contentassist.FQNLastSegmentFinder;
import org.eclipse.etrice.core.common.ui.editor.BaseDoubleClickStrategyProvider;
import org.eclipse.etrice.core.common.ui.editor.folding.FoldingRegionProvider;
import org.eclipse.etrice.core.common.ui.editor.model.BaseTokenTypeToPartitionMapper;
@@ -36,6 +37,7 @@ import org.eclipse.xtext.documentation.IEObjectDocumentationProviderExtension;
import org.eclipse.xtext.documentation.impl.MultiLineCommentDocumentationProvider;
import org.eclipse.xtext.ide.editor.syntaxcoloring.ISemanticHighlightingCalculator;
import org.eclipse.xtext.ui.editor.autoedit.AbstractEditStrategyProvider;
+import org.eclipse.xtext.ui.editor.contentassist.FQNPrefixMatcher;
import org.eclipse.xtext.ui.editor.doubleClicking.DoubleClickStrategyProvider;
import org.eclipse.xtext.ui.editor.folding.IFoldingRegionProvider;
import org.eclipse.xtext.ui.editor.hover.IEObjectHover;
@@ -64,6 +66,8 @@ public class RoomUiModule extends org.eclipse.etrice.core.ui.AbstractRoomUiModul
binder.bind(IKeywordHoverContentProvider.class).to(KeywordHoverContentProvider.class);
binder.bind(IEObjectHoverProvider.class).to(RoomHoverProvider.class);
binder.bind(IEObjectDocumentationProviderExtension.class).to(MultiLineCommentDocumentationProvider.class);
+
+ binder.bind(FQNPrefixMatcher.LastSegmentFinder.class).to(FQNLastSegmentFinder.class);
}
@Override
diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/dialogs/AbstractPropertyDialog.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/dialogs/AbstractPropertyDialog.java
index 8110adc2c..97a442e88 100644
--- a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/dialogs/AbstractPropertyDialog.java
+++ b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/dialogs/AbstractPropertyDialog.java
@@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
import java.util.Stack;
@@ -39,6 +40,7 @@ import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.common.util.Enumerator;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.databinding.EMFProperties;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
@@ -55,6 +57,7 @@ import org.eclipse.jface.fieldassist.ContentProposalAdapter;
import org.eclipse.jface.fieldassist.ControlDecoration;
import org.eclipse.jface.fieldassist.FieldDecoration;
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
+import org.eclipse.jface.fieldassist.IContentProposalProvider;
import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;
import org.eclipse.jface.fieldassist.TextContentAdapter;
import org.eclipse.jface.preference.IPreferenceStore;
@@ -80,6 +83,7 @@ import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.xtext.resource.IEObjectDescription;
+import org.eclipse.xtext.util.SimpleAttributeResolver;
import com.google.common.collect.Sets;
@@ -131,19 +135,31 @@ public abstract class AbstractPropertyDialog extends FormDialog {
static class DescriptionBased_Reference2StringConverter extends Converter {
- private EAttribute nameAttr;
+ private List<IEObjectDescription> candidates;
- DescriptionBased_Reference2StringConverter(Object type, EAttribute nameAttr) {
+ DescriptionBased_Reference2StringConverter(Object type, List<IEObjectDescription> candidates) {
super(type, String.class);
- this.nameAttr = nameAttr;
+ this.candidates = candidates;
}
@Override
public Object convert(Object fromObject) {
- if (fromObject instanceof IEObjectDescription)
- return ((IEObjectDescription)fromObject).getName();
+ // IEObjectDescription describes imported object, either by simple name or fqn
+ if (fromObject instanceof IEObjectDescription) {
+ return ((IEObjectDescription)fromObject).getName(); // <- getName() returns simple name or fqn based on existing imports
+ }
else if (fromObject instanceof EObject) {
- return ((EObject)fromObject).eGet(nameAttr);
+ // lookup of IEObjectDescription
+ final URI objURI = EcoreUtil.getURI((EObject) fromObject);
+ Optional<IEObjectDescription> match = candidates.stream().filter((eObjDesc) -> eObjDesc.getEObjectURI().equals(objURI)).findFirst();
+ if(match.isPresent()) {
+ // 1. try by URI - seems to be best choice
+ return match.get().getName().toString(); // <- getName() returns simple name or fqn based on existing imports
+ }
+ else {
+ // 2. should not happen - try simple name, does not work if namespace was not already imported
+ return SimpleAttributeResolver.NAME_RESOLVER.apply((EObject) fromObject);
+ }
}
return null;
@@ -492,11 +508,11 @@ public abstract class AbstractPropertyDialog extends FormDialog {
return combo;
}
- protected Combo createComboUsingDesc(Composite parent, String label, EObject obj, Object type, EReference ref, List<IEObjectDescription> candidates, EAttribute nameAttr, IValidator validator){
- return createComboUsingDesc(parent, label, obj, type, ref, candidates, nameAttr, validator, null);
+ protected Combo createComboUsingDesc(Composite parent, String label, EObject obj, Object type, EReference ref, List<IEObjectDescription> candidates, IValidator validator){
+ return createComboUsingDesc(parent, label, obj, type, ref, candidates, validator, null);
}
- protected Combo createComboUsingDesc(Composite parent, String label, EObject obj, Object type, EReference ref, List<IEObjectDescription> candidates, EAttribute nameAttr, IValidator validator, MultiValidator2 multiValidator) {
+ protected Combo createComboUsingDesc(Composite parent, String label, EObject obj, Object type, EReference ref, List<IEObjectDescription> candidates, IValidator validator, MultiValidator2 multiValidator) {
Label l = toolkit.createLabel(parent, label, SWT.NONE);
l.setLayoutData(new GridData(SWT.NONE));
@@ -505,7 +521,7 @@ public abstract class AbstractPropertyDialog extends FormDialog {
toolkit.adapt(comboViewer.getCombo(), true, true);
combo.setLayoutData(new GridData(SWT.HORIZONTAL));
combo.setVisibleItemCount(10);
- DescriptionBased_Reference2StringConverter r2s = new DescriptionBased_Reference2StringConverter(type, nameAttr);
+ DescriptionBased_Reference2StringConverter r2s = new DescriptionBased_Reference2StringConverter(type, candidates);
for (IEObjectDescription desc : candidates) {
comboViewer.add(r2s.convert(desc).toString());
}
@@ -545,7 +561,7 @@ public abstract class AbstractPropertyDialog extends FormDialog {
}
});
- SimpleContentProposalProvider proposalProvider = null;
+ IContentProposalProvider proposalProvider = null;
ContentProposalAdapter proposalAdapter = null;
KeyStroke keyStroke = KeyStroke.getInstance(SWT.CTRL, SWT.SPACE);
if (control instanceof Combo) {
@@ -558,7 +574,7 @@ public abstract class AbstractPropertyDialog extends FormDialog {
deco.show();
}
});
- proposalProvider = new SimpleContentProposalProvider(combo.getItems());
+ proposalProvider = new FilteredContentProposalProvider(combo.getItems());
proposalAdapter = new ContentProposalAdapter(combo, new ComboContentAdapter(), proposalProvider, keyStroke, null);
} else if (control instanceof Text) {
final Text text = (Text) control;
@@ -569,11 +585,10 @@ public abstract class AbstractPropertyDialog extends FormDialog {
deco.hide();
}
});
- proposalProvider = new SimpleContentProposalProvider(items);
+ proposalProvider = new FilteredContentProposalProvider(items);
proposalAdapter = new ContentProposalAdapter(text, new TextContentAdapter(), proposalProvider, keyStroke, null);
}
- proposalProvider.setFiltering(true);
proposalAdapter.setPropagateKeys(true);
proposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
}
diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/dialogs/FilteredContentProposalProvider.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/dialogs/FilteredContentProposalProvider.java
new file mode 100644
index 000000000..cdf5b2ed8
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/dialogs/FilteredContentProposalProvider.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * CONTRIBUTORS:
+ * Juergen Haug (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.common.base.dialogs;
+
+import java.util.ArrayList;
+
+import org.eclipse.etrice.core.common.ui.contentassist.FQNLastSegmentFinder;
+import org.eclipse.jface.fieldassist.ContentProposal;
+import org.eclipse.jface.fieldassist.IContentProposal;
+import org.eclipse.jface.fieldassist.IContentProposalProvider;
+import org.eclipse.xtext.ui.editor.contentassist.FQNPrefixMatcher;
+import org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher;
+
+public class FilteredContentProposalProvider implements IContentProposalProvider {
+
+ private String[] proposals;
+ private FQNPrefixMatcher matcher;
+
+ public FilteredContentProposalProvider(String... proposals) {
+ this.proposals = proposals;
+ this.matcher = new FQNPrefixMatcher();
+ this.matcher.setDelegate(new PrefixMatcher.IgnoreCase());
+ this.matcher.setLastSegmentFinder(new FQNLastSegmentFinder());
+ }
+
+ @Override
+ public IContentProposal[] getProposals(String contents, int position) {
+ ArrayList<ContentProposal> list = new ArrayList<>();
+ for (String proposal : proposals) {
+ if (matcher.isCandidateMatchingPrefix(proposal, contents)) {
+ list.add(new ContentProposal(proposal));
+ }
+ }
+ return list.toArray(new IContentProposal[list.size()]);
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/ActorContainerRefPropertyDialog.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/ActorContainerRefPropertyDialog.java
index 3193aa4a2..3e223fc50 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/ActorContainerRefPropertyDialog.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/ActorContainerRefPropertyDialog.java
@@ -211,8 +211,8 @@ public class ActorContainerRefPropertyDialog extends AbstractPropertyDialog {
Text name = createText(body, "&Name:", ref, RoomPackage.eINSTANCE.getActorContainerRef_Name(), nv);
Combo refClass = refIsActor?
- createComboUsingDesc(body, "Actor &Class:", ref, ActorClass.class, RoomPackage.eINSTANCE.getActorRef_Type(), actors, RoomPackage.eINSTANCE.getRoomClass_Name(), pv)
- : createComboUsingDesc(body, "SubSystem &Class:", ref, SubSystemClass.class, RoomPackage.eINSTANCE.getSubSystemRef_Type(), actors, RoomPackage.eINSTANCE.getRoomClass_Name(), pv);
+ createComboUsingDesc(body, "Actor &Class:", ref, ActorClass.class, RoomPackage.eINSTANCE.getActorRef_Type(), actors, pv)
+ : createComboUsingDesc(body, "SubSystem &Class:", ref, SubSystemClass.class, RoomPackage.eINSTANCE.getSubSystemRef_Type(), actors, pv);
createDecorator(name, "invalid name");
createDecorator(refClass, "no class selected");
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/PortPropertyDialog.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/PortPropertyDialog.java
index 476d4430e..ff75788e5 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/PortPropertyDialog.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/PortPropertyDialog.java
@@ -269,7 +269,7 @@ public class PortPropertyDialog extends AbstractPropertyDialog {
}
Text name = createText(body, "&Name:", port, FSMPackage.eINSTANCE.getAbstractInterfaceItem_Name(), nv);
- Combo protocol = createComboUsingDesc(body, "&Protocol:", port, GeneralProtocolClass.class, RoomPackage.eINSTANCE.getPort_Protocol(), protocols, RoomPackage.eINSTANCE.getRoomClass_Name(), pv);
+ Combo protocol = createComboUsingDesc(body, "&Protocol:", port, GeneralProtocolClass.class, RoomPackage.eINSTANCE.getPort_Protocol(), protocols, pv);
Button conj = createCheck(body, "&Conjugated:", port, RoomPackage.eINSTANCE.getPort_Conjugated());
if (!internal && !refitem && (acc instanceof ActorClass))
createRelayCheck(body, notReferenced, mform.getToolkit());
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/SPPPropertyDialog.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/SPPPropertyDialog.java
index fb31b8763..47f13c89a 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/SPPPropertyDialog.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/SPPPropertyDialog.java
@@ -109,7 +109,7 @@ public class SPPPropertyDialog extends AbstractPropertyDialog {
}
Text name = createText(body, "Name:", spp, FSMPackage.eINSTANCE.getAbstractInterfaceItem_Name(), nv);
- Combo protocol = createComboUsingDesc(body, "Protocol:", spp, ProtocolClass.class, RoomPackage.eINSTANCE.getSPP_Protocol(), protocols, RoomPackage.eINSTANCE.getRoomClass_Name(), pv);
+ Combo protocol = createComboUsingDesc(body, "Protocol:", spp, ProtocolClass.class, RoomPackage.eINSTANCE.getSPP_Protocol(), protocols, pv);
if (!newSPP) {
// TODOHRR: check whether spp is used externally?

Back to the top