org.metawidget.swt.widgetbuilder.OverriddenWidgetBuilder Maven / Gradle / Ivy
// Metawidget
//
// This file is dual licensed under both the LGPL
// (http://www.gnu.org/licenses/lgpl-2.1.html) and the EPL
// (http://www.eclipse.org/org/documents/epl-v10.php). As a
// recipient of Metawidget, you may choose to receive it under either
// the LGPL or the EPL.
//
// Commercial licenses are also available. See http://metawidget.org
// for details.
package org.metawidget.swt.widgetbuilder;
import static org.metawidget.inspector.InspectionResultConstants.*;
import java.util.Map;
import org.eclipse.swt.widgets.Control;
import org.metawidget.swt.SwtMetawidget;
import org.metawidget.widgetbuilder.iface.WidgetBuilder;
/**
* WidgetBuilder for overridden widgets in SWT environments.
*
* Locates overridden widgets based on a name
attribute in their setData
.
*
* Because of the way SWT requires Control
s to nominate their Composite
* up-front (ie. in their constructor), the behaviour of OverriddenWidgetBuilder
is
* limited to only overriding Control
s within their immediate Composite
.
* Therefore OverriddenWidgetBuilder
will not work if used to override
* Control
s that are laid out inside, say, a TabFolderLayoutDecorator
.
*
* @author Richard Kennard
*/
public class OverriddenWidgetBuilder
implements WidgetBuilder {
//
// Public methods
//
public Control buildWidget( String elementName, Map attributes, SwtMetawidget metawidget ) {
String name = attributes.get( NAME );
if ( name == null ) {
return null;
}
for ( Control componentExisting : metawidget.getChildren() ) {
if ( name.equals( componentExisting.getData( NAME ) ) ) {
return componentExisting;
}
}
return null;
}
}