001: /* uDig - User Friendly Desktop Internet GIS client
002: * http://udig.refractions.net
003: * (C) 2004, Refractions Research Inc.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation;
008: * version 2.1 of the License.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: */
015: package net.refractions.udig.project.ui.summary;
016:
017: import org.eclipse.jface.viewers.ICellEditorValidator;
018: import org.eclipse.jface.viewers.ICellModifier;
019: import org.eclipse.jface.viewers.TextCellEditor;
020:
021: /**
022: * Simple data object that has title and information fields. If the modifier is set then the data can be edited. Th cell editor
023: * is always a {@link TextCellEditor} so the modifier should aways return a string. The validator by default always accept
024: * the result. For custom validation cell validator can be set.
025: * @author Jesse
026: * @since 1.1.0
027: */
028: public class SummaryData {
029: private static final ICellModifier DEFAULT_MODIFIER = new ICellModifier() {
030:
031: public boolean canModify(Object element, String property) {
032: return false;
033: }
034:
035: public Object getValue(Object element, String property) {
036: return null;
037: }
038:
039: public void modify(Object element, String property, Object value) {
040: }
041:
042: };
043: private static final ICellEditorValidator TRUE_VALIDATOR = new ICellEditorValidator() {
044:
045: public String isValid(Object value) {
046: return null;
047: }
048:
049: };
050: private String title;
051: private String info;
052: private ICellModifier modifier = DEFAULT_MODIFIER;
053: private ICellEditorValidator validator = TRUE_VALIDATOR;
054: private SummaryData[] children;
055: private SummaryData parent;
056:
057: /**
058: * new instance. data has no children and no parent and is not editable
059: * @param title title/property name of the data item
060: * @param info the information to display. toString is called on the item to display it.
061: *
062: */
063: public SummaryData(String title, Object info) {
064: this .title = title;
065: if (info != null)
066: this .info = info.toString();
067: }
068:
069: public String getInfo() {
070: return info;
071: }
072:
073: public void setInfo(String info) {
074: this .info = info;
075: }
076:
077: public String getTitle() {
078: return title;
079: }
080:
081: public void setTitle(String title) {
082: this .title = title;
083: }
084:
085: /**
086: * gets the items to display as children of this object
087: *
088: * @return the items to display as children of this object
089: */
090: public SummaryData[] getChildren() {
091: if (children == null)
092: return new SummaryData[0];
093:
094: SummaryData[] data = new SummaryData[children.length];
095: System.arraycopy(children, 0, data, 0, data.length);
096: return data;
097: }
098:
099: public void setChildren(SummaryData[] children) {
100: SummaryData[] data;
101: if (children == null) {
102: data = new SummaryData[0];
103: } else {
104: data = new SummaryData[children.length];
105: System.arraycopy(children, 0, data, 0, data.length);
106: }
107:
108: this .children = data;
109: }
110:
111: /**
112: * @return the cell modifier that can edit this data.
113: */
114: public ICellModifier getModifier() {
115: return modifier;
116: }
117:
118: /**
119: * Sets the cell modifier used for this data item. The property can be ignored and the element will always be
120: * the {@link SummaryData} object. The newValue passed to the modify methods will always be a String
121: *
122: * @param modifier
123: */
124: public void setModifier(ICellModifier modifier) {
125: if (modifier == null) {
126: throw new NullPointerException();
127: }
128: this .modifier = modifier;
129: }
130:
131: public ICellEditorValidator getValidator() {
132: return validator;
133: }
134:
135: public void setValidator(ICellEditorValidator validator) {
136: if (validator == null) {
137: throw new NullPointerException();
138: }
139:
140: this .validator = validator;
141: }
142:
143: public SummaryData getParent() {
144: return parent;
145: }
146:
147: public void setParent(SummaryData parent) {
148: this.parent = parent;
149: }
150: }
|