001: package com.bostechcorp.cbesb.console.client.dialogs;
002:
003: import java.util.HashMap;
004: import java.util.Map;
005:
006: import com.bostechcorp.cbesb.console.client.Admin;
007: import com.bostechcorp.cbesb.console.client.endpoint.EndpointBase;
008: import com.bostechcorp.cbesb.console.common.Constants;
009: import com.bostechcorp.cbesb.console.i18n.ConsoleMessages;
010: import com.bostechcorp.cbesb.console.rpc.JmxOperation;
011: import com.bostechcorp.cbesb.console.rpc.JmxOperationAsync;
012: import com.google.gwt.core.client.GWT;
013: import com.google.gwt.user.client.rpc.ServiceDefTarget;
014: import com.google.gwt.user.client.ui.Button;
015: import com.google.gwt.user.client.ui.ChangeListener;
016: import com.google.gwt.user.client.ui.ClickListener;
017: import com.google.gwt.user.client.ui.DialogBox;
018: import com.google.gwt.user.client.ui.FlexTable;
019: import com.google.gwt.user.client.ui.FlowPanel;
020: import com.google.gwt.user.client.ui.HTML;
021: import com.google.gwt.user.client.ui.HasHorizontalAlignment;
022: import com.google.gwt.user.client.ui.HorizontalPanel;
023: import com.google.gwt.user.client.ui.TextBox;
024: import com.google.gwt.user.client.ui.VerticalPanel;
025: import com.google.gwt.user.client.ui.Widget;
026:
027: public class SettingDialogReadOnly extends DialogBox implements
028: ClickListener, ChangeListener {
029:
030: VerticalPanel mainPanel = new VerticalPanel();
031: /**
032: * @gwt.typeArgs <java.lang.String,java.lang.String>
033: */
034: HashMap propertiesMap = new HashMap();
035: /**
036: * @gwt.typeArgs <java.lang.String,java.lang.String>
037: */
038:
039: Map oldMap = new HashMap();
040:
041: protected Button saveButton;
042: protected FlexTable orderTable;
043: protected String type;
044: protected String componentName;
045: protected String suName;
046: protected String endpointName;
047: protected String saName;
048: protected Button resetButton;
049: protected EndpointBase parentAdmin;
050: final Button cancelButton = new Button();
051:
052: public SettingDialogReadOnly(EndpointBase parentAdmin,
053: String saName, String suName, String type,
054: String componentName, String endpointName,
055: String[][] properties) {
056: this .parentAdmin = parentAdmin;
057: this .saName = saName;
058: this .suName = suName;
059: this .type = type;
060: this .componentName = componentName;
061: this .endpointName = endpointName;
062: // setTitle(title);
063: setText(((ConsoleMessages) GWT.create(ConsoleMessages.class))
064: .Setting());
065: setWidget(mainPanel);
066:
067: orderTable = new FlexTable();
068: orderTable.setStyleName("PopupTable");
069: orderTable.setWidth("350px");
070: orderTable.setBorderWidth(3);
071: int i = 0;
072: int k = 0;
073: int j = 0;
074: boolean flag3 = false;
075: boolean flag1 = false;
076: boolean flag2 = false;
077: int totalSize = properties.length;
078: for (; i < totalSize; i++) {
079: if (totalSize < 20) {
080: if (i < 10) {
081: addColumn(flag1, i, i, 0, properties);
082: } else if (i < 20) {
083: addColumn(flag2, k, i, 1, properties);
084: k++;
085: }
086: } else if (totalSize < 30) {
087: if (i < 15) {
088: addColumn(flag1, i, i, 0, properties);
089: } else if (i < 30) {
090: addColumn(flag2, k, i, 1, properties);
091: k++;
092: }
093: } else if (totalSize < 40) {
094: if (i < 20) {
095: addColumn(flag1, i, i, 0, properties);
096: } else if (i < 40) {
097: addColumn(flag2, k, i, 1, properties);
098: k++;
099: }
100: } else if (totalSize < 60) {
101: if (i < 20) {
102: addColumn(flag1, i, i, 0, properties);
103: } else if (i < 40) {
104: addColumn(flag2, k, i, 1, properties);
105: k++;
106: } else if (i < 60) {
107: addColumn(flag3, j, i, 2, properties);
108: k++;
109: }
110: }
111: }
112:
113: final FlowPanel flowPanel = new FlowPanel();
114:
115: this .AddButton(flowPanel);
116:
117: int l = 0;
118: int span = 0;
119: if (i < 10) {
120: l = i + 1;
121: span = 2;
122: } else if (i < 20) {
123: l = 11;
124: span = 4;
125: } else if (i < 30) {
126: l = 16;
127: span = 4;
128: } else if (i < 40) {
129: l = 21;
130: span = 4;
131: } else if (i < 60) {
132: l = 21;
133: span = 6;
134: }
135:
136: orderTable.setWidget(l, 0, flowPanel);
137: orderTable.getCellFormatter().setHorizontalAlignment(l, 0,
138: HasHorizontalAlignment.ALIGN_RIGHT);
139: orderTable.getFlexCellFormatter().setColSpan(l, 0, span);
140: flowPanel.setWidth("280px");
141:
142: mainPanel.add(orderTable);
143: initContent();
144: this .setPopupPosition(100, 50);
145: show();
146: this .center();
147: }
148:
149: protected void AddButton(FlowPanel flowPanel) {
150: flowPanel.add(cancelButton);
151: cancelButton.setWidth("80px");
152: cancelButton.setText(((ConsoleMessages) GWT
153: .create(ConsoleMessages.class)).Cancel());
154: cancelButton.addClickListener(this );
155:
156: }
157:
158: private void initContent() {
159: }
160:
161: public void onClick(Widget sender) {
162:
163: hideDialog();
164: }
165:
166: public JmxOperationAsync getJmxOperationAsyncFromModule() {
167: JmxOperationAsync jmxOp;
168: jmxOp = (JmxOperationAsync) GWT.create(JmxOperation.class);
169: ServiceDefTarget jmxConnectTarget = (ServiceDefTarget) jmxOp;
170: String relativeUrl = GWT.getModuleBaseURL()
171: + Constants.JMX_CLIENT_SERVLET;
172: jmxConnectTarget.setServiceEntryPoint(relativeUrl);
173: return jmxOp;
174: }
175:
176: public void hideDialog() {
177:
178: hide();
179: this .removeFromParent();
180: }
181:
182: public void addColumn(boolean isCreate, int k, int i, int column,
183: String properties[][]) {
184: if (!isCreate) {
185: HorizontalPanel titlePanel = new HorizontalPanel();
186: titlePanel.add(new HTML("<h5>"
187: + ((ConsoleMessages) GWT
188: .create(ConsoleMessages.class)).Property()
189: + "</h5>", false));
190: titlePanel.add(new HTML("<h5>"
191: + ((ConsoleMessages) GWT
192: .create(ConsoleMessages.class)).Value()
193: + "</h5>", false));
194: orderTable.setWidget(0, column, titlePanel);
195: isCreate = true;
196: }
197: HorizontalPanel propertiesPanel = new HorizontalPanel();
198: HTML propertyName = new HTML(properties[i][0] + ": ", false);
199: propertyName.setTitle(properties[i][0]);
200: propertiesPanel.add(propertyName);
201: propertiesPanel.setCellHorizontalAlignment(propertyName,
202: HasHorizontalAlignment.ALIGN_CENTER);
203: TextBox valueText = new TextBox();
204: valueText.setText(properties[i][1]);
205: valueText.addChangeListener(this );
206: propertiesPanel.add(valueText);
207: oldMap.put(properties[i][0], properties[i][1]);
208: orderTable.setWidget(k + 1, column, propertiesPanel);
209: orderTable.getCellFormatter().setHorizontalAlignment(k + 1,
210: column, HasHorizontalAlignment.ALIGN_RIGHT);
211: }
212:
213: public void onChange(Widget sender) {
214: if (sender instanceof TextBox) {
215: TextBox textBox = (TextBox) sender;
216: String name = "";
217: String value = textBox.getText();
218: HorizontalPanel h = (HorizontalPanel) textBox.getParent();
219: for (int i = 0, n = h.getWidgetCount(); i < n; ++i) {
220: Widget w = h.getWidget(i);
221: if (w instanceof HTML) {
222: HTML html = (HTML) w;
223: name = html.getTitle();
224: if (!value.equals((String) oldMap.get(name))) {
225: propertiesMap.put(name, value);
226: } else {
227: propertiesMap.remove(name);
228: }
229: break;
230: }
231: }
232: }
233: }
234:
235: }
|