001: /*
002: * CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
003: * NETSCAPE COMMUNICATIONS CORPORATION
004: *
005: * Copyright (c) 1996 Netscape Communications Corporation.
006: * All Rights Reserved.
007: * Use of this Source Code is subject to the terms of the applicable
008: * license agreement from Netscape Communications Corporation.
009: *
010: * ==> MCW 07/97 <==
011: */
012:
013: package components;
014:
015: import netscape.application.Bitmap;
016: import netscape.application.Button;
017: import netscape.application.Color;
018: import netscape.application.DragDestination;
019: import netscape.application.DragSession;
020: import netscape.application.Graphics;
021: import netscape.application.Image;
022: import netscape.application.ListItem;
023: import netscape.application.Popup;
024: import netscape.application.Point;
025: import netscape.application.Rect;
026:
027: import graphical.MouseOverGridView;
028: import graphical.PopupCellEditor;
029:
030: import soif.Taxonomy;
031: import soif.TaxonomyNode;
032:
033: import util.BTreeNode;
034:
035: import com.indius.grid.IGridCellEditor;
036: import com.indius.grid.IGridRowEditView;
037: import com.indius.grid.NullValue;
038:
039: /**
040: * RDPropertyGridView extends IGridEditView. Implements support for
041: * popup and checkbox cells. (MCW)
042: */
043:
044: public class RDPropertyGridView extends MouseOverGridView implements
045: DragDestination {
046: private boolean m_editable;
047: private Image m_editableImage;
048: private Image m_noneditableImage;
049: private Image m_selectedImage;
050: private boolean m_updated = false;
051:
052: private String m_editableFields = null; // Editable field names
053:
054: private Taxonomy m_taxonomy;
055:
056: public RDPropertyGridView(int x, int y, int w, int h,
057: Taxonomy taxonomy) {
058: super (x, y, w, h);
059:
060: m_taxonomy = taxonomy;
061: initPropertyGridView();
062: }
063:
064: public void initPropertyGridView() {
065: m_editableImage = new Bitmap(Header.piece,
066: Header.pieceImageSize.width,
067: Header.pieceImageSize.height);
068:
069: m_noneditableImage = new Bitmap(Header.piecelocked,
070: Header.pieceImageSize.width,
071: Header.pieceImageSize.height);
072:
073: m_selectedImage = new Bitmap(Header.pieceselected,
074: Header.pieceImageSize.width,
075: Header.pieceImageSize.height);
076: }
077:
078: /**
079: * editableView - returns the editable stat of a view. (MCW)
080: */
081: public boolean editableView() {
082: return m_editable;
083: }
084:
085: /**
086: * setEditableView - Sets the editable state of a view. (MCW)
087: */
088: public void setEditableView(boolean flag) {
089: m_editable = flag;
090: }
091:
092: /**
093: * updatedView - returns the update status of a view. (MCW)
094: */
095: public boolean updatedView() {
096: return m_updated;
097: }
098:
099: /**
100: * setUpdatedView - Sets the updated status of a view. (MCW)
101: */
102: public void setUpdatedView(boolean flag) {
103: m_updated = flag;
104: }
105:
106: /**
107: * setEditableFields - list of editable field names
108: */
109: public void setEditableFields(String fieldNames) {
110: m_editableFields = fieldNames;
111: }
112:
113: public boolean isEditable(int r) {
114: while (grid().getValue(r, 1).toString().length() == 0) {
115: r--;
116: }
117:
118: String fieldName = grid().getValue(r, 1).toString();
119:
120: if ((m_editableFields.indexOf("," + fieldName) == -1)
121: && (m_editableFields.indexOf(fieldName + ",") == -1)) {
122: return false;
123: }
124:
125: return true;
126: }
127:
128: /**
129: * onPressCell override. Used to change the state of a checkbox
130: * cell on a mouse click. (MCW)
131: */
132: public void onPressCell(int r, int c) {
133: super .onPressCell(r, c);
134: createGridCellEditor(r, 2);
135: }
136:
137: /**
138: * editable override. Returns the editable state of a cell. (MCW)
139: */
140: public boolean editable(int r, int c) {
141: return isEditable(r);
142: }
143:
144: /**
145: * setEditableRow - Set up row as editable/non-editable. (MCW)
146: */
147: public void setEditableRow(int r, boolean flag) {
148: if (flag == true) {
149: grid().setValue(r, 0, m_editableImage);
150: } else {
151: grid().setValue(r, 0, m_noneditableImage);
152: }
153:
154: return;
155: }
156:
157: /**
158: * createGridCellEditor - Create editor at specified location. (MCW)
159: */
160: public void createGridCellEditor(int r, int c) {
161: deleteGridCellEditor(true); // destroy any existing cell editor
162: m_editRow = r;
163: m_editColumn = c;
164: createGridCellEditor();
165: }
166:
167: /**
168: * paintCellForeground override - Display selected image
169: */
170: public void paintCellForeground(Graphics g, int r, int c, Rect rect) {
171: if (c == 0) {
172: // Draw selected image or let Indius draw default image.
173: if (isSelected(r) == true) {
174: m_selectedImage.drawCentered(g, rect);
175: return;
176: }
177: }
178:
179: super .paintCellForeground(g, r, c, rect);
180: }
181:
182: /*******************/
183: /* DragDestination */
184: /*******************/
185:
186: public boolean dragEntered(DragSession ds) {
187: return m_editable;
188: }
189:
190: public boolean dragMoved(DragSession ds) {
191: return true;
192: }
193:
194: public void dragExited(DragSession ds) {
195: return;
196: }
197:
198: public boolean dragDropped(DragSession ds) {
199: if (m_editable == false) {
200: return false;
201: }
202:
203: Point destPoint = ds.destinationMousePoint();
204: int r = locateRow(destPoint.y, 0);
205: int i = r;
206:
207: // Label is blank when the field has multiple values, so backup
208: // to last non-blank entry for field name.
209: while (grid().getValue(i, 1).toString().length() == 0) {
210: i--;
211: }
212:
213: if (grid().getValue(i, 1).toString().equalsIgnoreCase(
214: "classification") == false) {
215: return false; // Can only drag into classification
216: }
217:
218: ListItem li = (ListItem) ds.data(); // Get dropped item
219: BTreeNode btn = (BTreeNode) li.data();
220: Object o = btn.getValue();
221:
222: if (o instanceof TaxonomyNode) {
223: grid().setValue(r, 2, ((TaxonomyNode) o).getId());
224: addDirtyRect(cellRect(r, 2)); // Refresh classification cell
225: deleteGridCellEditor(false); // Destroy existing editor, dump changes
226: }
227:
228: m_updated = true;
229: return true;
230: }
231:
232: public DragDestination acceptsDrag(DragSession ds, int x, int y) {
233: return this ;
234: }
235:
236: public IGridCellEditor newGridCellEditor(int r, int c) {
237:
238: if (c != 2) { // Not interested unless it is value column
239: return super .newGridCellEditor(r, c);
240: }
241:
242: // Label is blank when the field has multiple values, so backup
243: // to last non-blank entry for field name.
244: int i = r;
245:
246: while (grid().getValue(i, 1).toString().length() == 0) {
247: i--;
248: }
249:
250: if (grid().getValue(i, 1).toString().equalsIgnoreCase(
251: "classification") == true) {
252: String selected = grid().getValue(r, 2).toString();
253: PopupCellEditor e = new PopupCellEditor();
254: m_taxonomy.binaryTree.resetEnumeration();
255:
256: for (i = 0; m_taxonomy.binaryTree.hasMoreElements(true); i++) {
257: m_taxonomy.binaryTree.nextElement(true);
258: Object o = m_taxonomy.binaryTree.getValue();
259:
260: if (o instanceof TaxonomyNode) {
261: String item = ((TaxonomyNode) o).getId();
262: e.addItem(item, item);
263:
264: if (selected.compareTo(item) == 0) {
265: e.selectItemAt(i);
266: }
267: }
268: }
269:
270: return e;
271: }
272:
273: return super.newGridCellEditor(r, c);
274: }
275: }
|