001: package org.romaframework.aspect.view.echo2.component;
002:
003: import nextapp.echo2.app.Color;
004: import nextapp.echo2.app.Column;
005: import nextapp.echo2.app.Component;
006: import nextapp.echo2.app.Grid;
007: import nextapp.echo2.app.Label;
008: import nextapp.echo2.app.Style;
009:
010: import org.romaframework.aspect.view.echo2.form.EntityForm;
011: import org.romaframework.aspect.view.echo2.look.LookAndFeelManager;
012: import org.romaframework.core.config.RomaApplicationContext;
013: import org.romaframework.core.domain.message.Message;
014: import org.romaframework.core.domain.message.MessageResponseListener;
015: import org.romaframework.core.domain.message.MessageYesNoCancel;
016: import org.romaframework.core.flow.ObjectContext;
017: import org.romaframework.module.portal.PortalPage;
018:
019: import tucana.echo2.app.widgetdash.DefaultWidgetContainer;
020: import tucana.echo2.app.widgetdash.WidgetContainer;
021: import tucana.echo2.app.widgetdash.WidgetIdentifier;
022:
023: public class DynaWidget extends DefaultWidgetContainer implements
024: Titleable, MessageResponseListener {
025:
026: public static final String PROPERTY_TITLE_BACKGROUND = "titleBackground";
027: public static final String PROPERTY_TITLE_FOREGROUND = "titleForeground";
028: public static final String PROPERTY_BODY_BACKGROUND = "bodyBackground";
029: public static final String PROPERTY_BODY_FOREGROUND = "bodyForeground";
030:
031: protected WidgetContainer processCloseContainer;
032:
033: public DynaWidget(WidgetIdentifier identifier, Component widget,
034: String title) {
035: super (identifier, widget, title);
036: }
037:
038: @Override
039: protected void processClose(WidgetContainer container) {
040: processCloseContainer = container;
041: if (searchForPortalPage(container)) {
042: MessageYesNoCancel msg = new MessageYesNoCancel(
043: "portletCloseMessage", "Chiudi Portlet", this ,
044: "$DynaWidget.closeWidget.message");
045: ObjectContext.getInstance().show(msg, "screen:popup");
046: } else
047: super .processClose(container);
048: }
049:
050: public void responseMessage(Message iMessage, Object iResponse) {
051: Boolean resp = (Boolean) iResponse;
052: if (resp != null) {
053: if (resp)
054: processComponentOnRemove(this );
055: super .processClose(processCloseContainer);
056: }
057: }
058:
059: private boolean searchForPortalPage(Component iComponent) {
060: Component[] components = iComponent.getComponents();
061: for (Component component : components) {
062: if (component instanceof Column) {
063: return searchForPortalPage(component);
064: } else if (component instanceof EntityForm) {
065: EntityForm form = (EntityForm) component;
066: Object content = form.getContent();
067: if (content instanceof PortalPage)
068: return true;
069: else
070: return false;
071: }
072: }
073: return false;
074: }
075:
076: private void processComponentOnRemove(Component iComponent) {
077: Component[] components = iComponent.getComponents();
078: for (Component component : components) {
079: if (component instanceof Column) {
080: processComponentOnRemove(component);
081: } else if (component instanceof EntityForm) {
082: EntityForm form = (EntityForm) component;
083: Object content = form.getContent();
084: if (content instanceof PortalPage)
085: ((PortalPage) content).removeFromPreferences();
086: }
087: }
088: }
089:
090: public void setTitleBackground(Color newValue) {
091: setProperty(PROPERTY_TITLE_BACKGROUND, newValue);
092: }
093:
094: public void setTitleForeground(Color newValue) {
095: setProperty(PROPERTY_TITLE_FOREGROUND, newValue);
096: }
097:
098: public void setBodyBackground(Color newValue) {
099: setProperty(PROPERTY_BODY_BACKGROUND, newValue);
100: }
101:
102: public void setBodyForeground(Color newValue) {
103: setProperty(PROPERTY_BODY_FOREGROUND, newValue);
104: }
105:
106: @Override
107: public void setStyle(Style newValue) {
108: super .setStyle(newValue);
109: if (newValue.getProperty(PROPERTY_TITLE_BACKGROUND) != null) {
110: titleButtonRow.setBackground((Color) newValue
111: .getProperty(PROPERTY_TITLE_BACKGROUND));
112: titleGrid.setBackground((Color) newValue
113: .getProperty(PROPERTY_TITLE_BACKGROUND));
114: }
115: if (newValue.getProperty(PROPERTY_TITLE_FOREGROUND) != null) {
116: titleLabel.setForeground((Color) newValue
117: .getProperty(PROPERTY_TITLE_FOREGROUND));
118: }
119: if (newValue.getProperty(PROPERTY_BODY_BACKGROUND) != null) {
120: bodyColumn.setBackground((Color) newValue
121: .getProperty(PROPERTY_BODY_BACKGROUND));
122: }
123: if (newValue.getProperty(PROPERTY_BODY_FOREGROUND) != null) {
124: getWidgetBody().setForeground(
125: (Color) newValue
126: .getProperty(PROPERTY_BODY_FOREGROUND));
127: }
128: }
129: }
|