From 554da314913781ad43cb9cd559a06d192a902eef Mon Sep 17 00:00:00 2001
From: Simon Barner <barner@fortiss.org>
Date: Wed, 10 Sep 2014 12:48:12 +0000
Subject: [PATCH] - Start collection of reusable widgets:   - ExtendedCCombo ->
 CCombo whose entries are linked with foreign data

---
 .../trunk/META-INF/MANIFEST.MF                |  3 +-
 .../base/ui/widget/ExtendedCCombo.java        | 78 +++++++++++++++++++
 .../tooling/base/ui/widget/package.html       |  8 ++
 3 files changed, 88 insertions(+), 1 deletion(-)
 create mode 100644 org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/widget/ExtendedCCombo.java
 create mode 100644 org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/widget/package.html

diff --git a/org.fortiss.tooling.base.ui/trunk/META-INF/MANIFEST.MF b/org.fortiss.tooling.base.ui/trunk/META-INF/MANIFEST.MF
index c15b3cf28..d51460421 100644
--- a/org.fortiss.tooling.base.ui/trunk/META-INF/MANIFEST.MF
+++ b/org.fortiss.tooling.base.ui/trunk/META-INF/MANIFEST.MF
@@ -35,4 +35,5 @@ Export-Package: org.fortiss.tooling.base.ui,
  org.fortiss.tooling.base.ui.preferences,
  org.fortiss.tooling.base.ui.properties.view,
  org.fortiss.tooling.base.ui.tablecell,
- org.fortiss.tooling.base.ui.utils
+ org.fortiss.tooling.base.ui.utils,
+ org.fortiss.tooling.base.ui.widget
diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/widget/ExtendedCCombo.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/widget/ExtendedCCombo.java
new file mode 100644
index 000000000..75d4620d5
--- /dev/null
+++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/widget/ExtendedCCombo.java
@@ -0,0 +1,78 @@
+/*--------------------------------------------------------------------------+
+$Id$
+|                                                                          |
+| Copyright 2014 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.widget;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * Extention of {@link CCombo} that links the combo box entries with foreign data that can be
+ * added using {@link #add(String, Object)} and queried using {@link #getObject(int)}.
+ * 
+ * @author diewald
+ * @author $Author$
+ * @version $Rev$
+ * @ConQAT.Rating RED Hash:
+ */
+public class ExtendedCCombo<T> extends CCombo {
+
+	/** Correlates the entries in the combobox with arbitrary objects */
+	private List<T> objectReferenceList;
+
+	/**
+	 * Constructor.
+	 * 
+	 * A CCombo is created by this class. Additionally, the layout is defined.
+	 */
+	public ExtendedCCombo(Composite parent, int style) {
+		super(parent, style);
+		objectReferenceList = new ArrayList<T>();
+
+		GridData propertyValueGridData = new GridData();
+		propertyValueGridData.grabExcessHorizontalSpace = true;
+		propertyValueGridData.horizontalAlignment = GridData.FILL;
+
+		this.setLayoutData(propertyValueGridData);
+		this.setEditable(false);
+	}
+
+	/** Adds a String to the CCombo-box and references an Object for this entry. */
+	public void add(String comboString, T referencedObject) {
+		if(comboString == null || comboString.isEmpty() || referencedObject == null)
+			return;
+
+		this.add(comboString);
+
+		objectReferenceList.add(referencedObject);
+	}
+
+	/** Returns the object(type T) stored at the given index. */
+	public T getObject(int index) {
+		return objectReferenceList.get(index);
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	protected void checkSubclass() {
+		// Allow subclassing by overriding this check.
+	}
+}
diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/widget/package.html b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/widget/package.html
new file mode 100644
index 000000000..a002c51c8
--- /dev/null
+++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/widget/package.html
@@ -0,0 +1,8 @@
+<!--  
+  $Id$
+  @version $Rev$
+  @ConQAT.Rating RED Hash: 
+-->
+<body>
+A collection of reusable widgets.
+</body>
-- 
GitLab