Skip to content
Snippets Groups Projects
Commit 554da314 authored by Simon Barner's avatar Simon Barner
Browse files

- Start collection of reusable widgets:

  - ExtendedCCombo -> CCombo whose entries are linked with foreign data
parent 08688851
No related branches found
No related tags found
No related merge requests found
......@@ -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
/*--------------------------------------------------------------------------+
$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.
}
}
<!--
$Id$
@version $Rev$
@ConQAT.Rating RED Hash:
-->
<body>
A collection of reusable widgets.
</body>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment