001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.visualweb.propertyeditors.binding;
042:
043: import org.netbeans.modules.visualweb.propertyeditors.binding.data.DataBindingHelper;
044: import java.awt.BorderLayout;
045: import java.awt.CardLayout;
046: import java.awt.Component;
047: import java.awt.Graphics;
048: import java.awt.GridBagConstraints;
049: import java.awt.GridBagLayout;
050: import java.awt.Insets;
051: import java.awt.Rectangle;
052: import java.awt.event.ActionEvent;
053: import java.awt.event.ActionListener;
054: import java.beans.PropertyChangeEvent;
055: import java.beans.PropertyChangeListener;
056: import java.beans.PropertyEditor;
057: import java.util.Vector;
058:
059: import javax.faces.application.Application;
060: import javax.faces.el.ValueBinding;
061: import javax.swing.ButtonGroup;
062: import javax.swing.ImageIcon;
063: import javax.swing.JLabel;
064: import javax.swing.JPanel;
065: import javax.swing.JRadioButton;
066: import javax.swing.JSeparator;
067: import javax.swing.JTextArea;
068: import javax.swing.SwingUtilities;
069: import javax.swing.UIManager;
070:
071: import org.openide.explorer.propertysheet.ExPropertyEditor;
072: import org.openide.explorer.propertysheet.PropertyEnv;
073: import org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEditor;
074:
075: import com.sun.rave.designtime.DesignProperty;
076: import com.sun.rave.designtime.faces.FacesBindingPropertyEditor;
077: import com.sun.rave.designtime.faces.FacesDesignContext;
078: import com.sun.rave.designtime.faces.FacesDesignProperty;
079: import org.netbeans.modules.visualweb.propertyeditors.binding.data.TabbedDataBindingPanel;
080: import org.netbeans.modules.visualweb.propertyeditors.util.Bundle;
081:
082: public class ValueBindingPropertyEditor implements PropertyEditor,
083: ExPropertyEditor, FacesBindingPropertyEditor,
084: BindingTargetCallback,
085: com.sun.rave.propertyeditors.binding.ValueBindingPropertyEditor {
086: /**
087: * Key used to get names of panel classes from the property descriptor.
088: */
089: public static final String BINDING_PANEL_CLASS_NAMES = "bindingPanelClassNames"; // NOI18N
090:
091: private static final Bundle bundle = Bundle
092: .getBundle(ValueBindingPropertyEditor.class);
093:
094: protected PropertyEditor delegatePropertyEditor;
095:
096: private Object value;
097:
098: protected Component customEditor;
099: private Vector listeners;
100:
101: private boolean useDelegatePropertyEditor;
102:
103: private class TabbedDataBindingPanelAdapter extends JPanel
104: implements EnhancedCustomPropertyEditor {
105: private TabbedDataBindingPanel tabbedDataBindingPanel;
106:
107: public TabbedDataBindingPanelAdapter(
108: BindingTargetCallback callback, DesignProperty prop,
109: Class[] bindingPanelClasses, boolean showExpr) {
110: setLayout(new BorderLayout(8, 8));
111:
112: tabbedDataBindingPanel = new TabbedDataBindingPanel(
113: callback, prop, bindingPanelClasses, showExpr);
114: add(tabbedDataBindingPanel, BorderLayout.CENTER);
115: }
116:
117: /* (non-Javadoc)
118: * @see org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEditor#getPropertyValue()
119: */
120: public Object getPropertyValue() throws IllegalStateException {
121: return ValueBindingPropertyEditor.this .getValue();
122: }
123: }
124:
125: private class TabbedDataBindingPanelWrapper extends JPanel
126: implements EnhancedCustomPropertyEditor {
127: private JRadioButton useValueButton;
128: private JRadioButton useBindingButton;
129: private ButtonGroup useValueUseBindingGroup;
130:
131: private static final String BINDING_CARD = "bindingCard"; // NOI18N
132: private static final String VALUE_CARD = "valueCard"; // NOI18N
133:
134: private CardLayout cardLayout;
135: private JPanel cardPanel;
136:
137: private TabbedDataBindingPanel tabbedDataBindingPanel;
138:
139: private Component delegateCustomEditorComponent;
140:
141: public TabbedDataBindingPanelWrapper(
142: BindingTargetCallback callback, DesignProperty prop,
143: Class[] bindingPanelClasses, boolean showExpr,
144: Component delegateCustomEditor) {
145: delegateCustomEditorComponent = delegateCustomEditor;
146:
147: setLayout(new GridBagLayout());
148: GridBagConstraints gridBagConstraints;
149:
150: useValueUseBindingGroup = new ButtonGroup();
151:
152: useBindingButton = new JRadioButton(bundle
153: .getMessage("LBL_UseBindingRadionButton")); // NOI18N
154: useBindingButton.setMnemonic(bundle.getMessage(
155: "LBL_UseBindingRadionButton_Mnemonic").charAt(0)); // NOI18N
156: useBindingButton.getAccessibleContext().setAccessibleName(
157: bundle.getMessage("LBL_UseBindingRadionButton")); // NOI18N
158: useBindingButton
159: .getAccessibleContext()
160: .setAccessibleDescription(
161: bundle
162: .getMessage("LBL_UseBindingRadionButton_A11YDescription")); // NOI18N
163: useValueUseBindingGroup.add(useBindingButton);
164:
165: gridBagConstraints = new GridBagConstraints();
166: gridBagConstraints.insets = new Insets(12, 12, 0, 0);
167: gridBagConstraints.anchor = GridBagConstraints.WEST;
168: gridBagConstraints.gridx = 0;
169: gridBagConstraints.gridy = 0;
170: add(useBindingButton, gridBagConstraints);
171:
172: useValueButton = new JRadioButton(bundle
173: .getMessage("LBL_UseValueRadionButton")); // NOI18N
174: useValueButton.setMnemonic(bundle.getMessage(
175: "LBL_UseValueRadionButton_Mnemonic").charAt(0)); // NOI18N
176: useValueButton.getAccessibleContext().setAccessibleName(
177: bundle.getMessage("LBL_UseValueRadionButton")); // NOI18N
178: useValueButton
179: .getAccessibleContext()
180: .setAccessibleDescription(
181: bundle
182: .getMessage("LBL_UseValueRadionButton_A11YDescription")); // NOI18N
183: useValueUseBindingGroup.add(useValueButton);
184:
185: gridBagConstraints = new GridBagConstraints();
186: gridBagConstraints.insets = new Insets(12, 12, 0, 11);
187: gridBagConstraints.anchor = GridBagConstraints.WEST;
188: gridBagConstraints.gridx = 1;
189: gridBagConstraints.gridy = 0;
190: add(useValueButton, gridBagConstraints);
191:
192: gridBagConstraints = new GridBagConstraints();
193: gridBagConstraints.gridx = 0;
194: gridBagConstraints.gridy = 1;
195: gridBagConstraints.gridwidth = 2;
196: gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
197: gridBagConstraints.anchor = GridBagConstraints.WEST;
198: gridBagConstraints.insets = new java.awt.Insets(12, 12, 0,
199: 11);
200: add(new JSeparator(), gridBagConstraints);
201:
202: cardLayout = new CardLayout();
203: cardPanel = new JPanel(cardLayout);
204: //Bug Fix 6335113
205: if ((bindingPanelClasses == null)
206: || (bindingPanelClasses.length == 1)) {
207: bindingPanelClasses = new Class[] {
208: DataBindingHelper.BIND_VALUE_TO_DATAPROVIDER,
209: DataBindingHelper.BIND_VALUE_TO_OBJECT };
210: }
211: tabbedDataBindingPanel = new TabbedDataBindingPanel(
212: callback, prop, bindingPanelClasses, showExpr);
213: cardPanel.add(tabbedDataBindingPanel, BINDING_CARD);
214:
215: if (delegateCustomEditor == null) {
216: JTextArea message = new JTextArea(bundle
217: .getMessage("MSG_EditValueInPropertySheet")); // NOI18N
218: message.setEditable(false);
219: message.setLineWrap(true);
220: message.setWrapStyleWord(true);
221: message.setBorder(null);
222: message.setBackground(UIManager
223: .getColor("Label.background")); // NOI18N
224: message
225: .getAccessibleContext()
226: .setAccessibleName(
227: bundle
228: .getMessage("MSG_EditValueInPropertySheet")); // NOI18N
229: message
230: .getAccessibleContext()
231: .setAccessibleDescription(
232: bundle
233: .getMessage("MSG_EditValueInPropertySheet")); // NOI18N
234: cardPanel.add(message, VALUE_CARD);
235: } else {
236: cardPanel.add(delegateCustomEditor, VALUE_CARD);
237: }
238:
239: gridBagConstraints = new GridBagConstraints();
240: gridBagConstraints.insets = new Insets(12, 12, 12, 11);
241: gridBagConstraints.anchor = GridBagConstraints.WEST;
242: gridBagConstraints.fill = GridBagConstraints.BOTH;
243: gridBagConstraints.gridx = 0;
244: gridBagConstraints.gridy = 2;
245: gridBagConstraints.gridwidth = 2;
246: gridBagConstraints.weightx = 1;
247: gridBagConstraints.weighty = 1;
248: add(cardPanel, gridBagConstraints);
249:
250: // set the state of radio buttons and the card panel
251: if (isPropertyBound()) {
252: useBindingButton.setSelected(true);
253: cardLayout.show(cardPanel, BINDING_CARD);
254: } else {
255: useValueButton.setSelected(true);
256: cardLayout.show(cardPanel, VALUE_CARD);
257: }
258:
259: // add listeners
260: useBindingButton.addActionListener(new ActionListener() {
261: public void actionPerformed(ActionEvent e) {
262: adjustUseValueUseBinding();
263: }
264: });
265: useValueButton.addActionListener(new ActionListener() {
266: public void actionPerformed(ActionEvent e) {
267: adjustUseValueUseBinding();
268: }
269: });
270: }
271:
272: public void addNotify() {
273: super .addNotify();
274: // now adjust initial focus...
275: cardPanel.requestFocus();
276: SwingUtilities.invokeLater(new Runnable() {
277: public void run() {
278: cardPanel.transferFocus();
279: }
280: });
281: }
282:
283: /**
284: *
285: */
286: void adjustUseValueUseBinding() {
287: if (useBindingButton.isSelected()) {
288: setUseDelegatePropertyEditor(false);
289: showBindingCard();
290: } else if (useValueButton.isSelected()) {
291: setUseDelegatePropertyEditor(true);
292: showValueCard();
293: }
294: }
295:
296: void showBindingCard() {
297: cardLayout.show(cardPanel, BINDING_CARD);
298: }
299:
300: void showValueCard() {
301: cardLayout.show(cardPanel, VALUE_CARD);
302: }
303:
304: /* (non-Javadoc)
305: * @see org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEditor#getPropertyValue()
306: */
307: public Object getPropertyValue() throws IllegalStateException {
308: if (isUseDelegatePropertyEditor()) {
309: if (delegateCustomEditorComponent instanceof EnhancedCustomPropertyEditor) {
310: Object propertyValue = ((EnhancedCustomPropertyEditor) delegateCustomEditorComponent)
311: .getPropertyValue();
312: setValueInternal(propertyValue);
313: setUseDelegatePropertyEditor(!isValueBindingValue());
314: return getValueInternal();
315: }
316: }
317: return ValueBindingPropertyEditor.this .getValue();
318: }
319: }
320:
321: public ValueBindingPropertyEditor() {
322: this (null);
323: }
324:
325: public ValueBindingPropertyEditor(PropertyEditor propertyEditor) {
326: delegatePropertyEditor = propertyEditor;
327: }
328:
329: // Return if the property is bound
330: protected boolean isPropertyBound() {
331: return (facesDesignProperty != null && facesDesignProperty
332: .isBound());
333: }
334:
335: // Return if the value is bound
336: protected boolean isValueBindingValue() {
337: return (value instanceof ValueBinding);
338: }
339:
340: // Return the value of value binding
341: protected Object getValueBindingValue() {
342: if (isValueBindingValue()) {
343: FacesDesignContext fctx = (FacesDesignContext) facesDesignProperty
344: .getDesignBean().getDesignContext();
345: ValueBinding valueBinding = ((ValueBinding) value);
346: return valueBinding.getValue(fctx.getFacesContext());
347: }
348: return null;
349: }
350:
351: // Return the mode of custom edior panel
352: protected boolean isUseDelegatePropertyEditor() {
353: return useDelegatePropertyEditor;
354: }
355:
356: // Set the mode of custom edior panel
357: protected void setUseDelegatePropertyEditor(boolean newUseValue) {
358: if (delegatePropertyEditor == null) {
359: useDelegatePropertyEditor = false;
360: } else {
361: if (useDelegatePropertyEditor == newUseValue) {
362: return;
363: }
364: // set state
365: useDelegatePropertyEditor = newUseValue;
366: }
367: }
368:
369: protected void setValueInternal(Object newValue) {
370: value = newValue;
371: }
372:
373: protected Object getValueInternal() {
374: return value;
375: }
376:
377: // PropertyEditor2 implementation
378:
379: protected DesignProperty designProperty;
380: protected FacesDesignProperty facesDesignProperty;
381:
382: public void setDesignProperty(DesignProperty prop) {
383: designProperty = prop;
384: if (prop instanceof FacesDesignProperty) {
385: facesDesignProperty = (FacesDesignProperty) prop;
386: } else {
387: facesDesignProperty = null;
388: }
389: }
390:
391: // PropertyEditor implementation
392:
393: /* (non-Javadoc)
394: * @see java.beans.PropertyEditor#supportsCustomEditor()
395: */
396: public boolean supportsCustomEditor() {
397: return true;
398: }
399:
400: /* (non-Javadoc)
401: * @see java.beans.PropertyEditor#getCustomEditor()
402: */
403: public Component getCustomEditor() {
404: // initialize the value
405: setValue(designProperty.getValue());
406:
407: // No delegate - most likely this editor was configured as the property editor
408: if (delegatePropertyEditor == null) {
409: customEditor = new TabbedDataBindingPanelAdapter(this ,
410: designProperty, (Class[]) designProperty
411: .getPropertyDescriptor().getValue(
412: BINDING_PANEL_CLASS_NAMES), true);
413: } else {
414: // Delegate present - create custom editor component using binding panel and custom editor component supplied delegate property editor
415: Component delegateCustomEditorComponent = null;
416: if (delegatePropertyEditor.supportsCustomEditor()) {
417: delegateCustomEditorComponent = delegatePropertyEditor
418: .getCustomEditor();
419: }
420: customEditor = new TabbedDataBindingPanelWrapper(this ,
421: designProperty, (Class[]) designProperty
422: .getPropertyDescriptor().getValue(
423: BINDING_PANEL_CLASS_NAMES), true,
424: delegateCustomEditorComponent);
425: }
426:
427: return customEditor;
428: }
429:
430: /* (non-Javadoc)
431: * @see java.beans.PropertyEditor#addPropertyChangeListener(java.beans.PropertyChangeListener)
432: */
433: public void addPropertyChangeListener(
434: PropertyChangeListener listener) {
435: // record the listener
436: if (listeners == null) {
437: listeners = new java.util.Vector();
438: }
439: listeners.addElement(listener);
440:
441: // add to the delegate when going to/from bound state
442: if (delegatePropertyEditor != null) {
443: delegatePropertyEditor.addPropertyChangeListener(listener);
444: }
445: }
446:
447: /* (non-Javadoc)
448: * @see java.beans.PropertyEditor#removePropertyChangeListener(java.beans.PropertyChangeListener)
449: */
450: public void removePropertyChangeListener(
451: PropertyChangeListener listener) {
452: // remove the listener
453: if (listeners == null) {
454: return;
455: }
456: listeners.removeElement(listener);
457:
458: // remove from the delegate when going to/from bound state
459: if (delegatePropertyEditor != null) {
460: delegatePropertyEditor
461: .removePropertyChangeListener(listener);
462: }
463: }
464:
465: /**
466: * Report that we have been modified to any interested listeners.
467: */
468: void firePropertyChange() {
469: Vector targets;
470: synchronized (this ) {
471: if (listeners == null) {
472: return;
473: }
474: targets = (Vector) listeners.clone();
475: }
476:
477: // Tell our listeners that "everything" has changed.
478: PropertyChangeEvent evt = new PropertyChangeEvent(this , null,
479: null, null);
480:
481: for (int i = 0; i < targets.size(); i++) {
482: PropertyChangeListener target = (PropertyChangeListener) targets
483: .elementAt(i);
484: target.propertyChange(evt);
485: }
486: }
487:
488: /* (non-Javadoc)
489: * @see java.beans.PropertyEditor#getValue()
490: */
491: public Object getValue() {
492: if (isUseDelegatePropertyEditor()) {
493: if (delegatePropertyEditor != null) {
494: setValueInternal(delegatePropertyEditor.getValue());
495: setUseDelegatePropertyEditor(!isValueBindingValue());
496: }
497: }
498: return getValueInternal();
499: }
500:
501: /* (non-Javadoc)
502: * @see java.beans.PropertyEditor#setValue(java.lang.Object)
503: */
504: public void setValue(Object newValue) {
505: if (isPropertyBound()) {
506: // the property is bound so use the value binding as the value
507: Object valueBinding = facesDesignProperty.getValueBinding();
508: // set private value
509: setValueInternal(valueBinding);
510: setUseDelegatePropertyEditor(false);
511: } else {
512: setValueInternal(newValue);
513: setUseDelegatePropertyEditor(true);
514: }
515: if (delegatePropertyEditor != null) {
516: delegatePropertyEditor.setValue(newValue);
517: }
518: }
519:
520: /* (non-Javadoc)
521: * @see java.beans.PropertyEditor#getJavaInitializationString()
522: */
523: public String getJavaInitializationString() {
524: if (isUseDelegatePropertyEditor()) {
525: if (delegatePropertyEditor != null) {
526: return delegatePropertyEditor
527: .getJavaInitializationString();
528: }
529: }
530:
531: if (isValueBindingValue()) {
532: // the value is bound - get the value of the value binding
533: if (delegatePropertyEditor != null) {
534: // set the value on delegate and then call getAsText() on it.
535: delegatePropertyEditor.setValue(getValueBindingValue());
536: return delegatePropertyEditor
537: .getJavaInitializationString();
538: }
539: } else {
540: if (delegatePropertyEditor != null) {
541: // set the value on delegate and then call getAsText() on it.
542: delegatePropertyEditor.setValue(getValueInternal());
543: return delegatePropertyEditor
544: .getJavaInitializationString();
545: }
546: }
547:
548: return "";
549: }
550:
551: /* (non-Javadoc)
552: * @see java.beans.PropertyEditor#getAsText()
553: */
554: public String getAsText() {
555: if (isUseDelegatePropertyEditor()) {
556: if (delegatePropertyEditor != null) {
557: return delegatePropertyEditor.getAsText();
558: }
559: }
560:
561: if (isValueBindingValue()) {
562: return ((ValueBinding) getValueInternal())
563: .getExpressionString();
564: } else {
565: if (delegatePropertyEditor != null) {
566: // set the value on delegate and then call getAsText() on it.
567: delegatePropertyEditor.setValue(getValueInternal());
568: return delegatePropertyEditor.getAsText();
569: }
570: }
571:
572: if (getValueInternal() == null) {
573: return "";
574: }
575:
576: return String.valueOf(getValueInternal());
577: }
578:
579: /* (non-Javadoc)
580: * @see java.beans.PropertyEditor#setAsText(java.lang.String)
581: */
582: public void setAsText(String text) throws IllegalArgumentException {
583: if (isUseDelegatePropertyEditor()) {
584: if (delegatePropertyEditor != null) {
585: delegatePropertyEditor.setAsText(text);
586: }
587: } else {
588: text = text.trim();
589: if (text.startsWith("#{") && text.endsWith("}")) { //NOI18N
590: FacesDesignContext fctx = (FacesDesignContext) designProperty
591: .getDesignBean().getDesignContext();
592: Application app = fctx.getFacesContext()
593: .getApplication();
594: setValueInternal(app.createValueBinding(text));
595: } else if (text.length() > 0) {
596: if (delegatePropertyEditor != null) {
597: delegatePropertyEditor.setAsText(text);
598: setValueInternal(delegatePropertyEditor.getValue());
599: }
600: } else {
601: setValueInternal(facesDesignProperty.getUnsetValue());
602: }
603: }
604: }
605:
606: /* (non-Javadoc)
607: * @see java.beans.PropertyEditor#getTags()
608: */
609: public String[] getTags() {
610: if (isUseDelegatePropertyEditor()) {
611: if (delegatePropertyEditor != null) {
612: return delegatePropertyEditor.getTags();
613: }
614: }
615:
616: if (isValueBindingValue()) {
617: return null;
618: } else {
619: if (delegatePropertyEditor != null) {
620: return delegatePropertyEditor.getTags();
621: }
622: }
623: return null;
624: }
625:
626: /* (non-Javadoc)
627: * @see java.beans.PropertyEditor#isPaintable()
628: */
629: public boolean isPaintable() {
630: if (isUseDelegatePropertyEditor()) {
631: if (delegatePropertyEditor != null) {
632: return delegatePropertyEditor.isPaintable();
633: }
634: }
635:
636: if (isValueBindingValue()) {
637: // special handling of Boolean or boolean typed property to avoid ClassCastException in NetBeans propertysheet code
638: Class c = designProperty.getPropertyDescriptor()
639: .getPropertyType();
640: if ((c == Boolean.class) || (c == boolean.class)) {
641: return true;
642: }
643: }
644: return false;
645: }
646:
647: private static final ImageIcon BOUND_ICON = new ImageIcon(
648: ValueBindingPropertyEditor.class
649: .getResource("img/bound.png"));
650:
651: /* (non-Javadoc)
652: * @see java.beans.PropertyEditor#paintValue(java.awt.Graphics, java.awt.Rectangle)
653: */
654: public void paintValue(Graphics gfx, Rectangle box) {
655: if (!isPaintable())
656: return;
657:
658: if (isUseDelegatePropertyEditor()) {
659: if (delegatePropertyEditor != null) {
660: delegatePropertyEditor.paintValue(gfx, box);
661: }
662: return;
663: }
664:
665: if (isValueBindingValue()) {
666: // special handling of Boolean or boolean typed property to avoid ClassCastException in NetBeans propertysheet code
667: Class c = designProperty.getPropertyDescriptor()
668: .getPropertyType();
669: if ((c == Boolean.class) || (c == boolean.class)) {
670: JLabel lbl = new JLabel(BOUND_ICON, JLabel.LEFT);
671: String text = getAsText();
672: lbl.setText(text == null ? "" : text); //NOI18N
673: lbl.setBounds(box);
674: // get the forground color from the graphics object as this may be a select row of the
675: // property sheet in which the foreground needs to be selected foreground
676: lbl.setForeground(gfx.getColor());
677: lbl.paint(gfx);
678: }
679: }
680: }
681:
682: // BindingTargetCallback implementation
683:
684: /* (non-Javadoc)
685: * @see com.sun.rave.propertyeditors.binding.BindingTargetCallback#refresh()
686: */
687: public void refresh() {
688: // not a gui - do nothing
689: }
690:
691: /* (non-Javadoc)
692: * @see com.sun.rave.propertyeditors.binding.BindingTargetCallback#setNewExpressionText(java.lang.String)
693: */
694: public void setNewExpressionText(String newExpr) {
695: // convert to value binding
696: if (newExpr.startsWith("#{") && newExpr.endsWith("}")) { //NOI18N
697: FacesDesignContext fctx = (FacesDesignContext) designProperty
698: .getDesignBean().getDesignContext();
699: Application app = fctx.getFacesContext().getApplication();
700: setValueInternal(app.createValueBinding(newExpr));
701: // switch the mode immidiately to use the Use Binding panels so that correct value i.e.
702: // value binding is returned
703: setUseDelegatePropertyEditor(false);
704: if (delegatePropertyEditor != null) {
705: delegatePropertyEditor.setValue(getValueBindingValue());
706: }
707: } else {
708: setValueInternal(facesDesignProperty.getUnsetValue());
709: // switch the mode immidiately to use the Use Value panels
710: setUseDelegatePropertyEditor(true);
711: if (delegatePropertyEditor != null) {
712: delegatePropertyEditor.setValue(facesDesignProperty
713: .getUnsetValue());
714: }
715: }
716: }
717:
718: /* (non-Javadoc)
719: * @see org.openide.explorer.propertysheet.ExPropertyEditor#attachEnv(org.openide.explorer.propertysheet.PropertyEnv)
720: */
721: public void attachEnv(PropertyEnv env) {
722: if (delegatePropertyEditor instanceof ExPropertyEditor) {
723: ((ExPropertyEditor) delegatePropertyEditor).attachEnv(env);
724: }
725: }
726: }
|