|
@@ -1,192 +1,180 @@ |
1 |
1 |
|
package com.temp.client.foundation.widget.dialog; |
2 |
2 |
|
|
3 |
|
- |
import java.util.List; |
4 |
|
- |
|
5 |
|
- |
import com.temp.client.foundation.widget.LeftRightSiblings; |
6 |
|
- |
import com.temp.client.foundation.widget.OurPushButton; |
7 |
|
- |
import com.temp.shared.utils.StringUtils; |
8 |
|
- |
|
9 |
3 |
|
import com.google.gwt.dom.client.Element; |
10 |
|
- |
import com.google.gwt.event.dom.client.ClickEvent; |
11 |
|
- |
import com.google.gwt.event.dom.client.ClickHandler; |
|
4 |
+ |
import com.google.gwt.event.dom.client.*; |
12 |
5 |
|
import com.google.gwt.user.client.Timer; |
13 |
|
- |
import com.google.gwt.user.client.Window; |
14 |
|
- |
import com.google.gwt.user.client.ui.ButtonBase; |
15 |
|
- |
import com.google.gwt.user.client.ui.DialogBox; |
16 |
|
- |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
17 |
|
- |
import com.google.gwt.user.client.ui.HasVerticalAlignment; |
18 |
|
- |
import com.google.gwt.user.client.ui.HorizontalPanel; |
19 |
|
- |
import com.google.gwt.user.client.ui.Label; |
20 |
|
- |
import com.google.gwt.user.client.ui.ScrollPanel; |
21 |
|
- |
import com.google.gwt.user.client.ui.VerticalPanel; |
22 |
|
- |
import com.google.gwt.user.client.ui.Widget; |
|
6 |
+ |
import com.google.gwt.user.client.*; |
|
7 |
+ |
import com.google.gwt.user.client.ui.*; |
|
8 |
+ |
import com.temp.client.foundation.widget.*; |
|
9 |
+ |
import com.temp.shared.utils.*; |
|
10 |
+ |
|
|
11 |
+ |
import java.util.*; |
23 |
12 |
|
|
24 |
13 |
|
public class PopUpDialogBox extends DialogBox { |
25 |
14 |
|
private static final int POPUP_CONTENTS_HEIGHT_PX = 400; |
26 |
|
- |
private static final String HEADER_STYLE_NAME = "popUpDialogBox-header"; |
27 |
|
- |
private static final String HEADER_CONTENTS_STYLE_NAME = "popUpDialogBox-header-contents"; |
28 |
|
- |
private static final String TITLE_STYLE_NAME = "popUpDialogBox-title"; |
29 |
|
- |
private static final String CONTENTS_STYLE_NAME = "popUpDialogBox-contents"; |
30 |
|
- |
|
31 |
|
- |
private VerticalPanel contentsPanel = new VerticalPanel(); |
32 |
|
- |
private VerticalPanel headerWidgetPanel = new VerticalPanel(); |
33 |
|
- |
private ScrollPanel contentsScrollPanel = new ScrollPanel(contentsPanel); |
34 |
|
- |
private int contentsPanelInitialSize = 0; |
|
15 |
+ |
private static final String HEADER_STYLE_NAME = "popUpDialogBox-header"; |
|
16 |
+ |
private static final String HEADER_CONTENTS_STYLE_NAME = "popUpDialogBox-header-contents"; |
|
17 |
+ |
private static final String TITLE_STYLE_NAME = "popUpDialogBox-title"; |
|
18 |
+ |
private static final String CONTENTS_STYLE_NAME = "popUpDialogBox-contents"; |
|
19 |
+ |
|
|
20 |
+ |
private VerticalPanel contentsPanel = new VerticalPanel(); |
|
21 |
+ |
private VerticalPanel headerWidgetPanel = new VerticalPanel(); |
|
22 |
+ |
private ScrollPanel contentsScrollPanel = new ScrollPanel( contentsPanel ); |
|
23 |
+ |
private int contentsPanelInitialSize = 0; |
35 |
24 |
|
private VerticalPanel mainPanel = new VerticalPanel(); |
36 |
|
- |
private Label titleLabel = new Label(); |
|
25 |
+ |
private Label titleLabel = new Label(); |
37 |
26 |
|
private boolean donotScroll = false; |
38 |
27 |
|
|
39 |
28 |
|
public PopUpDialogBox() { |
40 |
|
- |
this(null, false, false, true); |
|
29 |
+ |
this( null, false, false, true ); |
41 |
30 |
|
} |
42 |
31 |
|
|
43 |
|
- |
public PopUpDialogBox(boolean donotScroll) { |
44 |
|
- |
this(null, donotScroll, false, true); |
|
32 |
+ |
public PopUpDialogBox( boolean donotScroll ) { |
|
33 |
+ |
this( null, donotScroll, false, true ); |
45 |
34 |
|
} |
46 |
35 |
|
|
47 |
|
- |
public PopUpDialogBox(Widget headerWidget) { |
48 |
|
- |
this(headerWidget, false, false, true); |
|
36 |
+ |
public PopUpDialogBox( Widget headerWidget ) { |
|
37 |
+ |
this( headerWidget, false, false, true ); |
49 |
38 |
|
} |
50 |
39 |
|
|
51 |
|
- |
public PopUpDialogBox(Widget headerWidget, boolean donotScroll, boolean showCloseButton){ |
52 |
|
- |
this(headerWidget, donotScroll, false, showCloseButton); |
|
40 |
+ |
public PopUpDialogBox( Widget headerWidget, boolean donotScroll, boolean showCloseButton ) { |
|
41 |
+ |
this( headerWidget, donotScroll, false, showCloseButton ); |
53 |
42 |
|
} |
54 |
43 |
|
|
55 |
44 |
|
// todo: headerWidget never used! |
56 |
|
- |
public PopUpDialogBox(Widget headerWidget, boolean donotScroll, boolean noHeader, boolean showCloseButton) { |
57 |
|
- |
if (!noHeader) { |
58 |
|
- |
titleLabel.setStylePrimaryName(TITLE_STYLE_NAME); |
|
45 |
+ |
public PopUpDialogBox( Widget headerWidget, boolean donotScroll, boolean noHeader, boolean showCloseButton ) { |
|
46 |
+ |
if ( !noHeader ) { |
|
47 |
+ |
titleLabel.setStylePrimaryName( TITLE_STYLE_NAME ); |
59 |
48 |
|
HorizontalPanel titleDownloadPanel = new HorizontalPanel(); |
60 |
|
- |
titleDownloadPanel.add(titleLabel); |
61 |
|
- |
titleDownloadPanel.setCellVerticalAlignment(titleLabel, HasVerticalAlignment.ALIGN_BOTTOM); |
62 |
|
- |
titleDownloadPanel.add(headerWidgetPanel); |
63 |
|
- |
titleDownloadPanel.setCellVerticalAlignment(headerWidgetPanel, HasVerticalAlignment.ALIGN_BOTTOM); |
|
49 |
+ |
titleDownloadPanel.add( titleLabel ); |
|
50 |
+ |
titleDownloadPanel.setCellVerticalAlignment( titleLabel, HasVerticalAlignment.ALIGN_BOTTOM ); |
|
51 |
+ |
titleDownloadPanel.add( headerWidgetPanel ); |
|
52 |
+ |
titleDownloadPanel.setCellVerticalAlignment( headerWidgetPanel, HasVerticalAlignment.ALIGN_BOTTOM ); |
64 |
53 |
|
|
65 |
|
- |
ButtonBase closeButton = new OurPushButton("x").add(new ClickHandler() { |
66 |
|
- |
public void onClick(ClickEvent e) { |
|
54 |
+ |
ButtonBase closeButton = new OurPushButton( "x" ).add( new ClickHandler() { |
|
55 |
+ |
public void onClick( ClickEvent e ) { |
67 |
56 |
|
hide(); |
68 |
57 |
|
} |
69 |
|
- |
}); |
70 |
|
- |
closeButton.setVisible(showCloseButton); |
|
58 |
+ |
} ); |
|
59 |
+ |
closeButton.setVisible( showCloseButton ); |
71 |
60 |
|
|
72 |
61 |
|
HorizontalPanel headerContents = new HorizontalPanel(); |
73 |
|
- |
headerContents.setWidth("100%"); |
74 |
|
- |
headerContents.setStylePrimaryName(HEADER_CONTENTS_STYLE_NAME); |
75 |
|
- |
headerContents.add(titleDownloadPanel); |
76 |
|
- |
headerContents.add(new LeftRightSiblings()); |
77 |
|
- |
headerContents.add(closeButton); |
78 |
|
- |
headerContents.setCellVerticalAlignment(closeButton, HasVerticalAlignment.ALIGN_MIDDLE); |
|
62 |
+ |
headerContents.setWidth( "100%" ); |
|
63 |
+ |
headerContents.setStylePrimaryName( HEADER_CONTENTS_STYLE_NAME ); |
|
64 |
+ |
headerContents.add( titleDownloadPanel ); |
|
65 |
+ |
headerContents.add( new LeftRightSiblings() ); |
|
66 |
+ |
headerContents.add( closeButton ); |
|
67 |
+ |
headerContents.setCellVerticalAlignment( closeButton, HasVerticalAlignment.ALIGN_MIDDLE ); |
79 |
68 |
|
|
80 |
69 |
|
HorizontalPanel headerPanel = new HorizontalPanel(); |
81 |
|
- |
headerPanel.setWidth("100%"); |
82 |
|
- |
headerPanel.setStylePrimaryName(HEADER_STYLE_NAME); |
83 |
|
- |
headerPanel.add(headerContents); |
|
70 |
+ |
headerPanel.setWidth( "100%" ); |
|
71 |
+ |
headerPanel.setStylePrimaryName( HEADER_STYLE_NAME ); |
|
72 |
+ |
headerPanel.add( headerContents ); |
84 |
73 |
|
|
85 |
|
- |
contentsPanel.setStylePrimaryName(CONTENTS_STYLE_NAME); |
86 |
|
- |
contentsPanel.setWidth("100%"); |
|
74 |
+ |
contentsPanel.setStylePrimaryName( CONTENTS_STYLE_NAME ); |
|
75 |
+ |
contentsPanel.setWidth( "100%" ); |
87 |
76 |
|
|
88 |
|
- |
mainPanel.add(headerPanel); |
89 |
|
- |
mainPanel.setCellHorizontalAlignment(headerPanel, HasHorizontalAlignment.ALIGN_CENTER); |
|
77 |
+ |
mainPanel.add( headerPanel ); |
|
78 |
+ |
mainPanel.setCellHorizontalAlignment( headerPanel, HasHorizontalAlignment.ALIGN_CENTER ); |
90 |
79 |
|
} |
91 |
80 |
|
|
92 |
|
- |
if(donotScroll) { |
93 |
|
- |
mainPanel.add(contentsPanel); |
94 |
|
- |
mainPanel.setCellHorizontalAlignment(contentsPanel, HasHorizontalAlignment.ALIGN_CENTER); |
|
81 |
+ |
if ( donotScroll ) { |
|
82 |
+ |
mainPanel.add( contentsPanel ); |
|
83 |
+ |
mainPanel.setCellHorizontalAlignment( contentsPanel, HasHorizontalAlignment.ALIGN_CENTER ); |
95 |
84 |
|
} else { |
96 |
|
- |
contentsScrollPanel.setHeight( "" + POPUP_CONTENTS_HEIGHT_PX + "px"); |
97 |
|
- |
mainPanel.add(contentsScrollPanel); |
98 |
|
- |
mainPanel.setCellHorizontalAlignment(contentsScrollPanel, HasHorizontalAlignment.ALIGN_CENTER); |
99 |
|
- |
} |
100 |
|
- |
mainPanel.setWidth("100%"); |
101 |
|
- |
setWidget(mainPanel); |
102 |
|
- |
setAnimationEnabled(true); |
103 |
|
- |
setGlassEnabled(true); |
|
85 |
+ |
contentsScrollPanel.setHeight( "" + POPUP_CONTENTS_HEIGHT_PX + "px" ); |
|
86 |
+ |
mainPanel.add( contentsScrollPanel ); |
|
87 |
+ |
mainPanel.setCellHorizontalAlignment( contentsScrollPanel, HasHorizontalAlignment.ALIGN_CENTER ); |
|
88 |
+ |
} |
|
89 |
+ |
mainPanel.setWidth( "100%" ); |
|
90 |
+ |
setWidget( mainPanel ); |
|
91 |
+ |
setAnimationEnabled( true ); |
|
92 |
+ |
setGlassEnabled( true ); |
104 |
93 |
|
hide(); |
105 |
94 |
|
contentsPanelInitialSize = contentsPanel.getElement().getOffsetHeight(); |
106 |
|
- |
} |
107 |
|
- |
|
|
95 |
+ |
} |
108 |
96 |
|
|
109 |
|
- |
protected void setHeaderWidget(Widget headerWidget) { |
|
97 |
+ |
protected void setHeaderWidget( Widget headerWidget ) { |
110 |
98 |
|
headerWidgetPanel.clear(); |
111 |
|
- |
if (headerWidget != null) { |
112 |
|
- |
headerWidgetPanel.add(headerWidget); |
|
99 |
+ |
if ( headerWidget != null ) { |
|
100 |
+ |
headerWidgetPanel.add( headerWidget ); |
113 |
101 |
|
} |
114 |
102 |
|
} |
115 |
103 |
|
|
116 |
|
- |
protected void setContentsAndShow(String title, List<Widget> contents) { |
117 |
|
- |
setContentsAndShow(title, (contents==null)?null: |
118 |
|
- |
contents.toArray(new Widget[contents.size()])); |
|
104 |
+ |
protected void setContentsAndShow( String title, List<Widget> contents ) { |
|
105 |
+ |
setContentsAndShow( title, (contents == null) ? null : |
|
106 |
+ |
contents.toArray( new Widget[contents.size()] ) ); |
119 |
107 |
|
} |
120 |
108 |
|
|
121 |
|
- |
protected void setContentsAndShow(String title, Widget ... contents) { |
122 |
|
- |
setContents(title,contents); |
|
109 |
+ |
protected void setContentsAndShow( String title, Widget... contents ) { |
|
110 |
+ |
setContents( title, contents ); |
123 |
111 |
|
centerAndShow(); |
124 |
112 |
|
} |
125 |
113 |
|
|
126 |
114 |
|
public void centerAndShow() { |
127 |
|
- |
setPopupPositionAndShow(new PositionCallback() { |
|
115 |
+ |
setPopupPositionAndShow( new PositionCallback() { |
128 |
116 |
|
@Override |
129 |
|
- |
public void setPosition(int offsetWidth, int offsetHeight) { |
|
117 |
+ |
public void setPosition( int offsetWidth, int offsetHeight ) { |
130 |
118 |
|
int left = (Window.getClientWidth() - offsetWidth) / 2; |
131 |
119 |
|
int top = (Window.getClientHeight() - offsetHeight) / 2; |
132 |
|
- |
setPopupPosition(left, top); |
|
120 |
+ |
setPopupPosition( left, top ); |
133 |
121 |
|
} |
134 |
|
- |
}); |
|
122 |
+ |
} ); |
135 |
123 |
|
final Timer resizeTimer = new Timer() { |
136 |
|
- |
public void run() { |
137 |
|
- |
if (resizeViewPanel()) { |
138 |
|
- |
cancel(); |
139 |
|
- |
} |
|
124 |
+ |
public void run() { |
|
125 |
+ |
if ( resizeViewPanel() ) { |
|
126 |
+ |
cancel(); |
140 |
127 |
|
} |
|
128 |
+ |
} |
141 |
129 |
|
}; |
142 |
|
- |
resizeTimer.scheduleRepeating(100); |
|
130 |
+ |
resizeTimer.scheduleRepeating( 100 ); |
143 |
131 |
|
} |
144 |
132 |
|
|
145 |
133 |
|
private void recenter() { |
146 |
134 |
|
int left = (Window.getClientWidth() - getElement().getClientWidth()) / 2; |
147 |
135 |
|
int top = (Window.getClientHeight() - getElement().getClientHeight()) / 2; |
148 |
|
- |
setPopupPosition(left, top); |
|
136 |
+ |
setPopupPosition( left, top ); |
149 |
137 |
|
} |
150 |
138 |
|
|
151 |
139 |
|
private boolean resizeViewPanel() { |
152 |
140 |
|
Element e = contentsPanel.getElement(); |
153 |
141 |
|
int contentsHeight = e.getOffsetHeight(); |
154 |
142 |
|
|
155 |
|
- |
if (contentsHeight <= contentsPanelInitialSize) { |
|
143 |
+ |
if ( contentsHeight <= contentsPanelInitialSize ) { |
156 |
144 |
|
return false; |
157 |
145 |
|
} |
158 |
146 |
|
|
159 |
|
- |
if (contentsHeight >= POPUP_CONTENTS_HEIGHT_PX) { |
|
147 |
+ |
if ( contentsHeight >= POPUP_CONTENTS_HEIGHT_PX ) { |
160 |
148 |
|
int scrollPanelWidth = e.getOffsetWidth(); |
161 |
149 |
|
scrollPanelWidth += 20; |
162 |
|
- |
contentsScrollPanel.setWidth("" + scrollPanelWidth + "px"); |
|
150 |
+ |
contentsScrollPanel.setWidth( "" + scrollPanelWidth + "px" ); |
163 |
151 |
|
recenter(); |
164 |
152 |
|
} |
165 |
153 |
|
return true; |
166 |
154 |
|
} |
167 |
155 |
|
|
168 |
|
- |
protected void setContents(String title, Widget ... contents) { |
169 |
|
- |
if(donotScroll) { |
170 |
|
- |
contentsPanel.setWidth(""); |
|
156 |
+ |
protected void setContents( String title, Widget... contents ) { |
|
157 |
+ |
if ( donotScroll ) { |
|
158 |
+ |
contentsPanel.setWidth( "" ); |
171 |
159 |
|
} else { |
172 |
|
- |
contentsScrollPanel.setWidth(""); |
|
160 |
+ |
contentsScrollPanel.setWidth( "" ); |
173 |
161 |
|
} |
174 |
162 |
|
|
175 |
|
- |
setTitle(title); |
|
163 |
+ |
setTitle( title ); |
176 |
164 |
|
|
177 |
|
- |
contentsPanel.clear(); |
178 |
|
- |
if (contents != null) { |
179 |
|
- |
for (Widget c : contents) { |
180 |
|
- |
contentsPanel.add(c); |
181 |
|
- |
} |
182 |
|
- |
} |
183 |
|
- |
} |
184 |
|
- |
|
185 |
|
- |
public void setTitle(String title){ |
186 |
|
- |
if (!StringUtils.isBlank(title)) { |
187 |
|
- |
titleLabel.setText(title); |
|
165 |
+ |
contentsPanel.clear(); |
|
166 |
+ |
if ( contents != null ) { |
|
167 |
+ |
for ( Widget c : contents ) { |
|
168 |
+ |
contentsPanel.add( c ); |
|
169 |
+ |
} |
|
170 |
+ |
} |
|
171 |
+ |
} |
|
172 |
+ |
|
|
173 |
+ |
public void setTitle( String title ) { |
|
174 |
+ |
if ( !StringUtils.isBlank( title ) ) { |
|
175 |
+ |
titleLabel.setText( title ); |
188 |
176 |
|
} else { |
189 |
|
- |
titleLabel.setText(""); |
|
177 |
+ |
titleLabel.setText( "" ); |
190 |
178 |
|
} |
191 |
|
- |
} |
|
179 |
+ |
} |
192 |
180 |
|
} |