From 0e2babab5b33491dde095d417e02b7958515f0cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20D=C3=B6bber?= <doebber@in.tum.de> Date: Tue, 7 Feb 2012 22:01:55 +0000 Subject: [PATCH] added data state variables and icons to field assist refs 563 --- .../base/ui/fieldassist/FieldAssist.java | 26 ++++++++++ .../fieldassist/FieldAssistImageRegistry.java | 47 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/FieldAssistImageRegistry.java diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/FieldAssist.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/FieldAssist.java index 0f44b0e05..6ad62e9e8 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/FieldAssist.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/FieldAssist.java @@ -22,6 +22,8 @@ import org.eclipse.jface.fieldassist.IContentProposal; import org.eclipse.jface.fieldassist.IContentProposalListener; import org.eclipse.jface.fieldassist.SimpleContentProposalProvider; import org.eclipse.jface.fieldassist.TextContentAdapter; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Text; /** @@ -70,6 +72,30 @@ public class FieldAssist { concreteProvider.getAutoActivationChars()); adapter.setPropagateKeys(true); adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_IGNORE); + + adapter.setLabelProvider(new LabelProvider() { + + /** {@inheritDoc} */ + @Override + public String getText(Object element) { + if (element instanceof IContentProposal) { + IContentProposal prop = (IContentProposal) element; + if (prop.getLabel() == null) { + return prop.getContent(); + } + return prop.getLabel(); + } + return element.toString(); + } + + /** {@inheritDoc} */ + @Override + public Image getImage(Object element) { + return FieldAssistImageRegistry.getIcon(getText(element)); + + } + + }); adapter.addContentProposalListener(new IContentProposalListener() { @Override diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/FieldAssistImageRegistry.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/FieldAssistImageRegistry.java new file mode 100644 index 000000000..ff53d1fc2 --- /dev/null +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/FieldAssistImageRegistry.java @@ -0,0 +1,47 @@ +/*--------------------------------------------------------------------------+ +$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $ +| | +| Copyright 2012 ForTISS GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.tooling.base.ui.fieldassist; + +import java.util.HashMap; + +import org.eclipse.swt.graphics.Image; + +/** + * Class for managing the icons to display in FieldAssist. + * + * @author doebber + * @author $Author: hoelzl $ + * @version $Rev: 18709 $ + * @ConQAT.Rating RED Hash: + */ +public class FieldAssistImageRegistry { + + /** Stores the mapping of displayed proposal string to icon. */ + private static HashMap<String, Image> map = new HashMap<String, Image>(); + + /** Assigns icon to proposal. */ + public static void put(String proposal, Image icon) { + map.put(proposal, icon); + } + + /** Returns the icons assigned to this proposal. */ + public static Image getIcon(String proposal) { + return map.get(proposal); + } + +} -- GitLab