001: package org.drools.eclipse.flow.common.view.datatype.editor.impl;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import java.io.Serializable;
020: import java.lang.reflect.InvocationTargetException;
021:
022: import org.drools.eclipse.DroolsEclipsePlugin;
023: import org.drools.eclipse.flow.common.datatype.DataTypeRegistry;
024: import org.drools.eclipse.flow.common.view.datatype.editor.Editor;
025: import org.drools.ruleflow.common.datatype.DataType;
026: import org.eclipse.swt.layout.FillLayout;
027: import org.eclipse.swt.widgets.Composite;
028:
029: /**
030: * Container for an editor.
031: *
032: * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
033: */
034: public class EditorComposite extends Composite {
035:
036: private DataTypeRegistry registry;
037: private Editor editor;
038:
039: public EditorComposite(Composite parent, int style,
040: DataTypeRegistry registry) {
041: super (parent, style);
042: this .registry = registry;
043: setLayout(new FillLayout());
044: editor = new EmptyEditor(this );
045: }
046:
047: public void setDataType(DataType type) {
048: ((Composite) editor).dispose();
049: if (type == null) {
050: editor = new EmptyEditor(this );
051: } else {
052: Class editorClass = null;
053: try {
054: editorClass = registry.getDataTypeInfo(type.getClass())
055: .getValueEditorClass();
056: editor = (Editor) editorClass.getConstructor(
057: new Class[] { Composite.class }).newInstance(
058: new Object[] { this });
059: } catch (IllegalArgumentException e) {
060: // "Could not find data type info for type " + type.getClass()
061: DroolsEclipsePlugin.log(e);
062: editor = new EmptyEditor(this );
063: } catch (InstantiationException e) {
064: // "Could not create editor for editor " + editorClass
065: DroolsEclipsePlugin.log(e);
066: editor = new EmptyEditor(this );
067: } catch (NoSuchMethodException e) {
068: // "Could not create editor for editor " + editorClass
069: DroolsEclipsePlugin.log(e);
070: editor = new EmptyEditor(this );
071: } catch (InvocationTargetException e) {
072: // "Could not create editor for editor " + editorClass
073: DroolsEclipsePlugin.log(e);
074: editor = new EmptyEditor(this );
075: } catch (IllegalAccessException e) {
076: // "Could not create editor for editor " + editorClass
077: DroolsEclipsePlugin.log(e);
078: editor = new EmptyEditor(this );
079: }
080: editor.setDataType(type);
081: layout();
082: }
083: }
084:
085: public void setValue(Serializable value) {
086: editor.setValue(value);
087: }
088:
089: public Serializable getValue() {
090: return editor.getValue();
091: }
092:
093: public void reset() {
094: editor.reset();
095: }
096:
097: public void setEnabled(boolean enabled) {
098: super .setEnabled(enabled);
099: ((Composite) editor).setEnabled(enabled);
100: }
101: }
|