001: /*
002: * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.romaframework.aspect.view.echo2.component;
018:
019: import nextapp.echo2.app.Button;
020: import nextapp.echo2.app.Font;
021: import nextapp.echo2.app.Row;
022: import nextapp.echo2.app.Style;
023: import nextapp.echo2.app.TextField;
024:
025: import org.romaframework.aspect.view.ViewConstants;
026: import org.romaframework.aspect.view.echo2.form.EntityForm;
027: import org.romaframework.aspect.view.echo2.form.FormUtil;
028: import org.romaframework.aspect.view.echo2.look.LookAndFeelManager;
029: import org.romaframework.aspect.view.form.ContentComponent;
030: import org.romaframework.core.Utility;
031: import org.romaframework.core.config.RomaApplicationContext;
032: import org.romaframework.core.schema.SchemaField;
033: import org.romaframework.core.schema.SchemaObject;
034:
035: import echopointng.KeyStrokeListener;
036: import echopointng.KeyStrokes;
037:
038: public class ComposedComponent extends Row implements ContentComponent {
039:
040: private TextField textComponent;
041: private Button button;
042:
043: protected ContentComponent containerComponent;
044: protected SchemaObject schemaInstance;
045: protected SchemaField schemaField;
046: protected Object content;
047:
048: protected ComposedComponent(EntityForm iForm, SchemaField iField) {
049: containerComponent = iForm;
050: textComponent = new TextField();
051:
052: RomaApplicationContext.getInstance().getBean(
053: LookAndFeelManager.class).assignStyle(textComponent,
054: null, "ComposedComponent.TextField");
055:
056: textComponent.setEnabled(false);
057: add(textComponent);
058:
059: button = new Button();
060: button.setActionCommand(ViewConstants.ACTION_PREFIX
061: + Utility.PACKAGE_SEPARATOR + iField.getName());
062: button.addActionListener(iForm);
063:
064: RomaApplicationContext.getInstance().getBean(
065: LookAndFeelManager.class).assignStyle(button, null,
066: "ComposedComponent.Lookup");
067:
068: if (button.getStyle() == null)
069: button.setText("...");
070: else
071: button.setText("");
072:
073: button.setActionCommand(ViewConstants.FIELD_PREFIX
074: + Utility.PACKAGE_SEPARATOR + iField.getName());
075: button.setProperty(FormUtil.METADATA_COMPONENT_OWNER, this );
076: add(button);
077:
078: // CAPTURE F2 KEY
079: KeyStrokeListener ks = new KeyStrokeListener();
080: ks.addKeyCombination(KeyStrokes.VK_F2,
081: ViewConstants.FIELD_PREFIX + Utility.PACKAGE_SEPARATOR
082: + iField.getName());
083: ks.addActionListener(iForm);
084: add(ks);
085: }
086:
087: public void setContent(Object content) {
088: this .content = content;
089:
090: String valueToRender = content != null
091: && content.toString() != null
092: && content.toString().length() > 0 ? content.toString()
093: : "";
094: textComponent.setText(valueToRender);
095: }
096:
097: public void destroy() {
098: if (content != null)
099: content = null;
100: }
101:
102: @Override
103: public void setStyle(Style newValue) {
104: Font font = (Font) newValue.getProperty("font");
105: if (font != null)
106: setFont(font);
107: else
108: super .setStyle(newValue);
109: }
110:
111: @Override
112: public void setFont(Font iFont) {
113: textComponent.setFont(iFont);
114: button.setFont(iFont);
115: }
116:
117: public TextField getTextComponent() {
118: return textComponent;
119: }
120:
121: public void render(ContentComponent iFormToRender) {
122: }
123:
124: public Button getButtonComponent() {
125: return button;
126: }
127:
128: public void close() {
129: }
130:
131: public void render() {
132: render(this );
133: }
134:
135: public void renderContent() {
136: }
137:
138: public ContentComponent getContainerComponent() {
139: return containerComponent;
140: }
141:
142: public void setMetaDataSchema(SchemaObject iSchema) {
143: schemaInstance = iSchema;
144: }
145:
146: public void setMetaDataField(SchemaField iField) {
147: schemaField = iField;
148: }
149:
150: public SchemaObject getSchemaInstance() {
151: return schemaInstance;
152: }
153:
154: public SchemaField getSchemaField() {
155: return schemaField;
156: }
157:
158: public Object getContent() {
159: return content;
160: }
161:
162: public void bind(SchemaField iSchemaField, Object iValue,
163: Object component) {
164: bind(iSchemaField, iValue, null);
165: }
166:
167: public void bind(SchemaField iSchemaField, Object iValue) {
168: containerComponent.bind(iSchemaField, iValue);
169: }
170:
171: public void handleException(Throwable t) {
172: containerComponent.handleException(t);
173: }
174:
175: @Override
176: public String toString() {
177: if (content != null)
178: return content.toString();
179: else
180: return super.toString();
181: }
182: }
|