001: package discRack.presentation.delements;
002:
003: import discRack.presentation.dpanels.*;
004:
005: import java.util.*;
006:
007: /**
008: * Represents a complex element - element made of simple elements and other
009: * complex elements and gives a panel for editing it's context.
010: *
011: * @author Sasa Bojanic
012: * @version 1.0
013: */
014: public class DComplexElement extends DSimpleElement {
015:
016: protected java.util.List complexStructure = new ArrayList();
017:
018: public DComplexElement(String name) {
019: super (name);
020: }
021:
022: /**
023: * Returns the collection of elements this element is made of.
024: */
025: public Collection toComplexType() {
026: return complexStructure;
027: }
028:
029: /**
030: * Returns the collection of strings that represents elements
031: * that this element is made of.
032: */
033: public Collection toComplexTypeValues() {
034: java.util.List l = new ArrayList();
035: Iterator it = complexStructure.iterator();
036: while (it.hasNext()) {
037: DSimpleElement el = (DSimpleElement) it.next();
038: l.add(el.toValue());
039: }
040: return l;
041: }
042:
043: /**
044: * Sets the element and all element it is made of to be
045: * read only or not.
046: */
047: public void setReadOnly(boolean ro) {
048: super .setReadOnly(ro);
049: Iterator it = complexStructure.iterator();
050: while (it.hasNext()) {
051: DSimpleElement el = (DSimpleElement) it.next();
052: el.setReadOnly(ro);
053: }
054: }
055:
056: public boolean isEmpty() {
057: boolean isEmpty = true;
058: Iterator it = complexStructure.iterator();
059: while (it.hasNext()) {
060: DSimpleElement el = (DSimpleElement) it.next();
061: isEmpty = isEmpty && el.isEmpty();
062: }
063: return isEmpty;
064: }
065:
066: public boolean isValid() {
067: boolean isValid = true;
068: Iterator it = complexStructure.iterator();
069: while (it.hasNext()) {
070: DSimpleElement el = (DSimpleElement) it.next();
071: isValid = isValid && el.isValid();
072: }
073: return isValid;
074: }
075:
076: public DPanel getPanel() {
077: DSimpleElement[] c = new DSimpleElement[complexStructure.size()];
078: complexStructure.toArray(c);
079: return new DGroupPanel(this , c, toName(), true, true);
080: }
081:
082: /** Gets the element that is placed at specified no. within structure. */
083: public DSimpleElement get(int no) {
084: try {
085: return (DSimpleElement) complexStructure.get(no);
086: } catch (Exception ex) {
087: return null;
088: }
089: }
090:
091: /**
092: * Sets the element that is placed at specified no. within structure
093: * to the specified value.
094: */
095: public void set(int no, Object value) {
096: DSimpleElement el;
097: try {
098: el = get(no);
099: } catch (Exception ex) {
100: el = null;
101: }
102: if (el != null) {
103: el.setValue(value);
104: }
105: }
106:
107: /** Gets the element with specified name from stucture. */
108: public DSimpleElement get(String name) {
109: Iterator it = complexStructure.iterator();
110: while (it.hasNext()) {
111: DSimpleElement el = (DSimpleElement) it.next();
112: if (el.name.equals(name)) {
113: return el;
114: }
115: }
116: return null;
117: }
118:
119: /**
120: * Sets the element with specified name from stucture to
121: * the specified value.
122: */
123: public void set(String name, Object value) {
124: DSimpleElement el = get(name);
125: if (el != null) {
126: el.setValue(value);
127: }
128: }
129:
130: public String toString() {
131: return name;
132: }
133:
134: protected void fillStructure() {
135: return;
136: }
137:
138: }
|