001: package org.drools.brms.client.common;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import com.google.gwt.user.client.ui.HTML;
020: import com.google.gwt.user.client.ui.HasHorizontalAlignment;
021: import com.google.gwt.user.client.ui.HasVerticalAlignment;
022: import com.google.gwt.user.client.ui.HorizontalPanel;
023: import com.google.gwt.user.client.ui.Image;
024: import com.google.gwt.user.client.ui.Label;
025: import com.google.gwt.user.client.ui.Widget;
026: import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
027:
028: /**
029: * This form style class is to be extended to provide
030: * "form style" dialogs (eg in a popup).
031: *
032: * @author Michael Neale
033: */
034: public class FormStyleLayout extends DirtyableComposite {
035:
036: private DirtyableFlexTable layout = new DirtyableFlexTable();
037: private FlexCellFormatter formatter = layout.getFlexCellFormatter();
038: private int numInLayout = 0;
039:
040: /**
041: * Create a new layout with a header and and icon.
042: */
043: public FormStyleLayout(String image, String title) {
044: addHeader(image, title);
045: initWidget(layout);
046: }
047:
048: /** This has no header */
049: public FormStyleLayout() {
050: initWidget(layout);
051: }
052:
053: /**
054: * Clears the layout table.
055: */
056: public void clear() {
057: numInLayout = 0;
058: this .layout.clear();
059: }
060:
061: /**
062: * Add a widget to the "form".
063: */
064: public void addAttribute(String lbl, Widget editor) {
065: HTML label = new HTML("<b>" + lbl + "</b>");
066: layout.setWidget(numInLayout, 0, label);
067: formatter.setAlignment(numInLayout, 0,
068: HasHorizontalAlignment.ALIGN_RIGHT,
069: HasVerticalAlignment.ALIGN_TOP);
070: layout.setWidget(numInLayout, 1, editor);
071: formatter.setAlignment(numInLayout, 1,
072: HasHorizontalAlignment.ALIGN_LEFT,
073: HasVerticalAlignment.ALIGN_TOP);
074:
075: numInLayout++;
076: }
077:
078: public void addWidget(Widget editor) {
079: layout.setWidget(numInLayout, 1, editor);
080: formatter.setAlignment(numInLayout, 1,
081: HasHorizontalAlignment.ALIGN_CENTER,
082: HasVerticalAlignment.ALIGN_TOP);
083: numInLayout++;
084: }
085:
086: /** Adds a widget that takes up a whole row. */
087: public void addRow(Widget w) {
088: layout.setWidget(numInLayout, 0, w);
089: formatter.setColSpan(numInLayout, 0, 2);
090: numInLayout++;
091: }
092:
093: /**
094: * Adds a header at the top.
095: */
096: protected void addHeader(String image, String title) {
097: Label name = new Label(title);
098: name.setStyleName("resource-name-Label");
099: doHeader(image, name);
100: }
101:
102: private void doHeader(String image, Widget title) {
103: layout.setWidget(0, 0, new Image(image));
104: formatter.setAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT,
105: HasVerticalAlignment.ALIGN_TOP);
106: layout.setWidget(0, 1, title);
107: numInLayout++;
108: }
109:
110: protected void addHeader(String image, String title,
111: Widget titleIcon) {
112: Label name = new Label(title);
113: name.setStyleName("resource-name-Label");
114: HorizontalPanel horiz = new HorizontalPanel();
115: horiz.add(name);
116: horiz.add(titleIcon);
117: doHeader(image, horiz);
118:
119: }
120:
121: public void setFlexTableWidget(int row, int col, Widget widget) {
122: layout.setWidget(row, col, widget);
123: }
124:
125: public boolean isDirty() {
126: return layout.hasDirty();
127: }
128:
129: }
|