Source Code Cross Referenced for CommonSpreadSheet.java in  » Project-Management » OpenProj » com » projity » pm » graphic » spreadsheet » common » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Project Management » OpenProj » com.projity.pm.graphic.spreadsheet.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:        The contents of this file are subject to the Common Public Attribution License 
003:        Version 1.0 (the "License"); you may not use this file except in compliance with 
004:        the License. You may obtain a copy of the License at 
005:        http://www.projity.com/license . The License is based on the Mozilla Public 
006:        License Version 1.1 but Sections 14 and 15 have been added to cover use of 
007:        software over a computer network and provide for limited attribution for the 
008:        Original Developer. In addition, Exhibit A has been modified to be consistent 
009:        with Exhibit B.
010:
011:        Software distributed under the License is distributed on an "AS IS" basis, 
012:        WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the 
013:        specific language governing rights and limitations under the License. The 
014:        Original Code is OpenProj. The Original Developer is the Initial Developer and 
015:        is Projity, Inc. All portions of the code written by Projity are Copyright (c) 
016:        2006, 2007. All Rights Reserved. Contributors Projity, Inc.
017:
018:        Alternatively, the contents of this file may be used under the terms of the 
019:        Projity End-User License Agreeement (the Projity License), in which case the 
020:        provisions of the Projity License are applicable instead of those above. If you 
021:        wish to allow use of your version of this file only under the terms of the 
022:        Projity License and not to allow others to use your version of this file under 
023:        the CPAL, indicate your decision by deleting the provisions above and replace 
024:        them with the notice and other provisions required by the Projity  License. If 
025:        you do not delete the provisions above, a recipient may use your version of this 
026:        file under either the CPAL or the Projity License.
027:
028:        [NOTE: The text of this license may differ slightly from the text of the notices 
029:        in Exhibits A and B of the license at http://www.projity.com/license. You should 
030:        use the latest text at http://www.projity.com/license for your modifications.
031:        You may not remove this license text from the source files.]
032:
033:        Attribution Information: Attribution Copyright Notice: Copyright � 2006, 2007 
034:        Projity, Inc. Attribution Phrase (not exceeding 10 words): Powered by OpenProj, 
035:        an open source solution from Projity. Attribution URL: http://www.projity.com 
036:        Graphic Image as provided in the Covered Code as file:  openproj_logo.png with 
037:        alternatives listed on http://www.projity.com/logo
038:
039:        Display of Attribution Information is required in Larger Works which are defined 
040:        in the CPAL as a work which combines Covered Code or portions thereof with code 
041:        not governed by the terms of the CPAL. However, in addition to the other notice 
042:        obligations, all copies of the Covered Code in Executable and Source Code form 
043:        distributed must, as a form of attribution of the original author, include on 
044:        each user interface screen the "OpenProj" logo visible to all users.  The 
045:        OpenProj logo should be located horizontally aligned with the menu bar and left 
046:        justified on the top left of the screen adjacent to the File menu.  The logo 
047:        must be at least 100 x 25 pixels.  When users click on the "OpenProj" logo it 
048:        must direct them back to http://www.projity.com.  
049:         */
050:        package com.projity.pm.graphic.spreadsheet.common;
051:
052:        import java.awt.Component;
053:        import java.awt.Container;
054:        import java.awt.Point;
055:        import java.awt.Rectangle;
056:        import java.awt.event.MouseEvent;
057:        import java.util.ArrayList;
058:        import java.util.EventListener;
059:        import java.util.EventObject;
060:        import java.util.LinkedList;
061:        import java.util.List;
062:
063:        import javax.swing.CellEditor;
064:        import javax.swing.JScrollPane;
065:        import javax.swing.JTable;
066:        import javax.swing.JViewport;
067:        import javax.swing.UIManager;
068:        import javax.swing.border.Border;
069:        import javax.swing.event.EventListenerList;
070:        import javax.swing.plaf.UIResource;
071:        import javax.swing.table.TableCellEditor;
072:        import javax.swing.table.TableModel;
073:
074:        import org.apache.commons.collections.CollectionUtils;
075:        import org.apache.commons.collections.Predicate;
076:
077:        import com.projity.configuration.Dictionary;
078:        import com.projity.field.FieldParseException;
079:        import com.projity.graphic.configuration.GraphicConfiguration;
080:        import com.projity.graphic.configuration.SpreadSheetFieldArray;
081:        import com.projity.graphic.configuration.shape.Colors;
082:        import com.projity.grouping.core.Node;
083:        import com.projity.grouping.core.NodeFactory;
084:        import com.projity.grouping.core.model.NodeModel;
085:        import com.projity.pm.graphic.ChangeAwareTextField;
086:        import com.projity.pm.graphic.model.cache.NodeModelCache;
087:        import com.projity.pm.graphic.model.event.CacheListener;
088:        import com.projity.pm.graphic.model.event.CompositeCacheEvent;
089:        import com.projity.pm.graphic.spreadsheet.SpreadSheetColumnModel;
090:        import com.projity.pm.graphic.spreadsheet.SpreadSheetModel;
091:        import com.projity.pm.graphic.spreadsheet.SpreadSheetUtils;
092:        import com.projity.pm.graphic.spreadsheet.editor.KeyboardFocusable;
093:        import com.projity.pm.graphic.spreadsheet.renderer.NameCellComponent;
094:        import com.projity.pm.graphic.spreadsheet.selection.SpreadSheetSelectionModel;
095:        import com.projity.pm.graphic.spreadsheet.selection.event.SelectionNodeEvent;
096:        import com.projity.pm.graphic.spreadsheet.selection.event.SelectionNodeListener;
097:        import com.projity.pm.graphic.timescale.ScaledScrollPane;
098:        import com.projity.server.access.ErrorLogger;
099:        import com.projity.util.Alert;
100:        import com.projity.workspace.SavableToWorkspace;
101:        import com.projity.workspace.WorkspaceSetting;
102:
103:        /**
104:         *  
105:         */
106:        public class CommonSpreadSheet extends CommonTable implements 
107:                CacheListener, SavableToWorkspace {
108:            /**
109:             * 
110:             */
111:            private static final long serialVersionUID = 2541466281456673698L;
112:            public static final String RESOURCE_CATEGORY = "resourceSpreadsheet";
113:            public static final String TASK_CATEGORY = "taskSpreadsheet";
114:
115:            protected SpreadSheetSelectionModel selection;
116:            protected String spreadSheetCategory = null;
117:            protected SpreadSheetRowHeader rowHeader;
118:            protected SpreadSheetCorner corner;
119:            protected int lastEditingRow = -1;
120:            protected boolean canModifyColumns = true;
121:            protected boolean canSelectFieldArray = true;
122:
123:            public CommonSpreadSheet() {
124:                super ();
125:                setGridColor(Colors.GRAY);
126:                putClientProperty("JTable.autoStartsEdit", Boolean.TRUE);
127:                setSurrendersFocusOnKeystroke(true);
128:                setAutoCreateColumnsFromModel(false);
129:                rowHeader = new SpreadSheetRowHeader(this );
130:                rowHeader.setRowHeight(getRowHeight());
131:
132:                setFocusCycleRoot(true);
133:
134:            }
135:
136:            public void cleanUp() {
137:                getCache().removeNodeModelListener((CacheListener) getModel());
138:            }
139:
140:            //	public void setModel(CommonSpreadSheetModel spreadSheetModel, DefaultTableColumnModel spreadSheetColumnModel) {
141:            //		
142:            //		setModel(spreadSheetModel);
143:            //	    setColumnModel(spreadSheetColumnModel);
144:            //	    
145:            //	    selection = new SpreadSheetSelectionModel(this);
146:            //		selection.setRowSelection(new SpreadSheetListSelectionModel(selection,
147:            //				true));
148:            //		selection.setColumnSelection(new SpreadSheetListSelectionModel(
149:            //				selection, false));
150:            //		setSelectionModel(selection.getRowSelection());
151:            //		createDefaultColumnsFromModel();
152:            //		getColumnModel().setSelectionModel(selection.getColumnSelection());
153:            //		
154:            //		registerEditors();
155:            //		initRowHeader(spreadSheetModel);
156:            //		initModel();
157:            //		initListeners();
158:            //		
159:            //		
160:            //
161:            //	}
162:
163:            //helper
164:            public void setCache(NodeModelCache cache) {
165:                ((CommonSpreadSheetModel) getModel()).setCache(cache);
166:            }
167:
168:            public NodeModelCache getCache() {
169:                TableModel model = getModel();
170:                if (model == null || !(model instanceof  CommonSpreadSheetModel))
171:                    return null;
172:                return ((CommonSpreadSheetModel) model).getCache();
173:            }
174:
175:            public void setFieldArray(ArrayList fieldArray) {
176:                ((SpreadSheetColumnModel) getColumnModel())
177:                        .setFieldArray(fieldArray);
178:                //
179:                //		((CommonSpreadSheetModel)getModel()).setFieldArray(fieldArray);
180:            }
181:
182:            public final ArrayList getFieldArray() {
183:                return ((CommonSpreadSheetModel) getModel()).getFieldArray();
184:            }
185:
186:            public final SpreadSheetFieldArray getFieldArrayWithWidths(
187:                    ArrayList fieldArray) {
188:                if (fieldArray == null)
189:                    fieldArray = getFieldArray();
190:                SpreadSheetColumnModel cols = (SpreadSheetColumnModel) getColumnModel();
191:                for (int i = 0; i < cols.getColumnCount(); i++)
192:                    ((SpreadSheetFieldArray) fieldArray).setWidth(i, cols
193:                            .getColumn(i).getWidth());
194:                return (SpreadSheetFieldArray) fieldArray;
195:            }
196:
197:            public final void setFieldArrayWithWidths(
198:                    SpreadSheetFieldArray fieldArray) {
199:                setFieldArray(fieldArray);
200:                SpreadSheetColumnModel cols = (SpreadSheetColumnModel) getColumnModel();
201:                for (int i = 0; i < cols.getColumnCount(); i++)
202:                    cols.getColumn(i).setWidth(fieldArray.getWidth(i));
203:            }
204:
205:            public void setRowHeight(int rowHeight) {
206:                super .setRowHeight(rowHeight);
207:                if (rowHeader != null)
208:                    rowHeader.setRowHeight(rowHeight);
209:            }
210:
211:            protected void initRowHeader(CommonSpreadSheetModel spreadSheetModel) {
212:                rowHeader.setModel(spreadSheetModel,
213:                        new SpreadSheetRowHeaderColumnModel());
214:                rowHeader.createDefaultColumnsFromModel();
215:            }
216:
217:            protected void initModel() {
218:
219:                GraphicConfiguration config = GraphicConfiguration
220:                        .getInstance();
221:                setRowHeight(config.getRowHeight());
222:                setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
223:                setCellSelectionEnabled(true);
224:                //setRowSelectionAllowed(true);
225:                //setColumnSelectionAllowed(true);
226:            }
227:
228:            protected void initListeners() {
229:            }
230:
231:            /**
232:             * @return Returns the selection.
233:             */
234:            public SpreadSheetSelectionModel getSelection() {
235:                return selection;
236:            }
237:
238:            public boolean isCellEditing(int row, int col) {
239:                return (!(isEditing() && getEditingRow() == row && getEditingColumn() == col));
240:            }
241:
242:            //editing for example
243:            public int[] finishCurrentOperations() {
244:                int[] rows = null;
245:                if (isEditing()) {
246:                    lastEditingRow = getEditingRow();
247:                    CellEditor editor = getCellEditor();
248:                    if (editor != null) {
249:                        rows = getSelectedRows();
250:                        editor.stopCellEditing();//editor.cancelCellEditing();
251:
252:                    }
253:                }
254:                //System.out.println("finishCurrentOperations()="+rows);
255:                return rows;
256:            }
257:
258:            //node selection
259:            protected EventListenerList selectionNodeListenerList = new EventListenerList();
260:
261:            public void addSelectionNodeListener(SelectionNodeListener l) {
262:                selectionNodeListenerList.add(SelectionNodeListener.class, l);
263:            }
264:
265:            public void removeSelectionNodeListener(SelectionNodeListener l) {
266:                selectionNodeListenerList
267:                        .remove(SelectionNodeListener.class, l);
268:            }
269:
270:            public SelectionNodeListener[] getSelectionNodeListeners() {
271:                return (SelectionNodeListener[]) selectionNodeListenerList
272:                        .getListeners(SelectionNodeListener.class);
273:            }
274:
275:            public void fireContentsChanged(Object source, List nodes,
276:                    Node currentNode) {
277:                Object[] listeners = selectionNodeListenerList
278:                        .getListenerList();
279:                SelectionNodeEvent e = null;
280:                for (int i = listeners.length - 2; i >= 0; i -= 2) {
281:                    if (listeners[i] == SelectionNodeListener.class) {
282:                        if (e == null) {
283:                            e = new SelectionNodeEvent(source,
284:                                    SelectionNodeEvent.SELECTION_CHANGED,
285:                                    nodes, currentNode,
286:                                    getSpreadSheetCategory());
287:                        }
288:                        ((SelectionNodeListener) listeners[i + 1])
289:                                .selectionChanged(e);
290:                    }
291:                }
292:            }
293:
294:            public EventListener[] getSelectionNodeListeners(Class listenerType) {
295:                return selectionNodeListenerList.getListeners(listenerType);
296:            }
297:
298:            public boolean isNodeDeletable(Node node) {
299:                return true;
300:            }
301:
302:            public boolean isNodeCuttable(Node node) {
303:                return true;
304:            }
305:
306:            public List getSelectedDeletableRows() {
307:                ArrayList list = getSelectedNodes();
308:                CollectionUtils.filter(list, new Predicate() {
309:                    public boolean evaluate(Object arg0) {
310:                        return isNodeDeletable((Node) arg0);
311:                    }
312:                });
313:                return list;
314:
315:            }
316:
317:            public List getSelectedCuttableRows(List nodes) {
318:                CollectionUtils.filter(nodes, new Predicate() {
319:                    public boolean evaluate(Object arg0) {
320:                        return isNodeCuttable((Node) arg0);
321:                    }
322:                });
323:                return nodes;
324:
325:            }
326:
327:            public ArrayList getSelectedNodes() {
328:                SpreadSheetModel model = (SpreadSheetModel) getModel();
329:                int[] rows = getSelectedRows();
330:                ArrayList nodes = new ArrayList(rows.length);
331:                for (int i = 0; i < rows.length; i++) {
332:                    nodes.add(model.getNode(rows[i]).getNode());
333:                }
334:                return nodes;
335:            }
336:
337:            public ArrayList getSelectedNodesImpl() {
338:                SpreadSheetModel model = (SpreadSheetModel) getModel();
339:                int[] rows = getSelectedRows();
340:                ArrayList nodes = new ArrayList(rows.length);
341:                for (int i = 0; i < rows.length; i++) {
342:                    nodes.add(model.getNode(rows[i]).getNode().getImpl());
343:                }
344:                return nodes;
345:            }
346:
347:            public ArrayList getSelectedFields() {
348:                if (getRowHeader().getSelectedColumns().length > 0)
349:                    return null;
350:                int[] columns = getSelectedColumns();
351:                ArrayList fields = new ArrayList(columns.length);
352:                List fieldArray = getFieldArray();
353:                for (int i = 0; i < columns.length; i++) {
354:                    fields.add(fieldArray.get(columns[i] + 1));
355:                }
356:                return fields;
357:            }
358:
359:            public ArrayList getSelectableFields() {
360:                List fa = getFieldArray();
361:                ArrayList fields = new ArrayList(fa.size());
362:                fields.addAll(fa);
363:                if (fields.size() > 0)
364:                    fields.remove(0); //ID not selectable
365:                return fields;
366:            }
367:
368:            public Object getCurrentRowImpl() {
369:                SpreadSheetModel model = (SpreadSheetModel) getModel();
370:                return model.getObjectInRow(getSelectedRow());
371:            }
372:
373:            public Node getCurrentRowNode() {
374:                SpreadSheetModel model = (SpreadSheetModel) getModel();
375:                int row = getCurrentRow();
376:                return model.getNodeInRow(row);
377:            }
378:
379:            public int getCurrentRow() {
380:                int row = getSelectedRow();
381:                if (row == -1)
382:                    row = getEditingRow();
383:                if (row == -1)
384:                    row = lastEditingRow;
385:                return row;
386:
387:            }
388:
389:            protected boolean cellEditable = true;
390:
391:            public boolean isCellEditable(int row, int col) {
392:                return (cellEditable) ? super .isCellEditable(row, col) : false;
393:            }
394:
395:            public void setCellEditable(boolean cellEditable) {
396:                this .cellEditable = cellEditable;
397:            }
398:
399:            // edit triggered by click
400:            public boolean editCellAt(int row, int column, EventObject e) {
401:                boolean b = super .editCellAt(row, column, e);
402:                if (b && editorComp != null) {
403:                    //    		System.out.println("editing cell at " + row + " " + column);
404:                    Component comp;
405:                    boolean nameCell = false;
406:                    if (editorComp instanceof  NameCellComponent) {
407:                        nameCell = true;
408:                        NameCellComponent nameCellComp = (NameCellComponent) editorComp;
409:                        comp = nameCellComp.getTextComponent();
410:                    } else
411:                        comp = editorComp;
412:
413:                    if (comp instanceof  KeyboardFocusable)
414:                        ((KeyboardFocusable) comp).selectAll(e == null);
415:
416:                    else if (comp instanceof  ChangeAwareTextField) {
417:                        ChangeAwareTextField text = ((ChangeAwareTextField) comp);
418:                        if (e == null) {
419:                            text.selectAll();
420:                        } else if (e instanceof  MouseEvent) {
421:                            if (nameCell) {
422:                                MouseEvent me = (MouseEvent) e;
423:                                Rectangle bounds = text.getBounds(null);
424:                                Rectangle cell = getCellRect(row, column, false);
425:                                bounds
426:                                        .setFrame(cell.getX() + bounds.getX(),
427:                                                cell.getY() + bounds.getY(),
428:                                                bounds.getWidth(), bounds
429:                                                        .getHeight());
430:                                if (bounds.contains(me.getPoint())) {
431:                                    text.selectAllOnNextCaretUpdate(); //to avoid diselection when the cell is clicked
432:                                } else { //because if it's outside there's no caret update
433:                                    text.requestFocus();
434:                                    text.selectAll();
435:                                }
436:                            } else
437:                                text.selectAllOnNextCaretUpdate(); //to avoid diselection when the cell is clicked
438:                        }
439:                        text.resetChange();
440:                    }
441:                }
442:                return b;
443:            }
444:
445:            protected boolean editOnSelect = false;
446:
447:            /**
448:             * @return Returns the editOnSelect.
449:             */
450:            public boolean isEditOnSelect() {
451:                return editOnSelect;
452:            }
453:
454:            /**
455:             * @param editOnSelect The editOnSelect to set.
456:             */
457:            public void setEditOnSelect(boolean editOnSelect) {
458:                this .editOnSelect = editOnSelect;
459:            }
460:
461:            public void changeSelection(int rowIndex, int columnIndex,
462:                    boolean toggle, boolean extend) {
463:                changeSelection(rowIndex, columnIndex, toggle, extend, true);
464:            }
465:
466:            public void changeSelection(int rowIndex, int columnIndex,
467:                    boolean toggle, boolean extend, boolean forwards) {
468:                super .changeSelection(rowIndex, columnIndex, toggle, extend);
469:                if (editOnSelect && !isEditing()) {
470:                    editCellAt(rowIndex, columnIndex); //TODO prevent setValueAt from being called because of this on selection
471:                } else {
472:                }
473:                if (forwards) {
474:                    rowHeader.clearSelection();
475:                    //rowHeader.changeSelection(rowIndex, columnIndex, toggle, extend,false);
476:                }
477:            }
478:
479:            public void clearSelection() {
480:                if (rowHeader != null)
481:                    rowHeader.clearSelection();
482:                super .clearSelection();
483:            }
484:
485:            /**
486:             * @return Returns the spreadSheetCategory.
487:             */
488:            public String getSpreadSheetCategory() {
489:                return spreadSheetCategory;
490:            }
491:
492:            /**
493:             * @param spreadSheetCategory The spreadSheetCategory to set.
494:             */
495:            public void setSpreadSheetCategory(String spreadSheetCategory) {
496:                this .spreadSheetCategory = spreadSheetCategory;
497:            }
498:
499:            public List getAvailableFields() {
500:                return SpreadSheetUtils
501:                        .getFieldsForCategory(getSpreadSheetCategory());
502:            }
503:
504:            protected void configureScrollPaneHeaders(JScrollPane scrollPane) {
505:                if (scrollPane instanceof  ScaledScrollPane)
506:                    scrollPane
507:                            .setColumnHeaderView(((ScaledScrollPane) scrollPane)
508:                                    .getTimeScaleComponent());
509:                else
510:                    scrollPane.setColumnHeaderView(getTableHeader());
511:                JViewport vp = new JViewport();
512:                vp.setView(rowHeader);
513:                vp.setPreferredSize(rowHeader.getPreferredSize());
514:                scrollPane.setRowHeader(vp);
515:                corner = new SpreadSheetCorner(this );
516:                scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, corner);
517:                //scrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER,new GradientCorner());
518:            }
519:
520:            protected void configureEnclosingScrollPane() {
521:                super .configureEnclosingScrollPane();
522:                Container p = getParent();
523:                if (p instanceof  JViewport) {
524:                    Container gp = p.getParent();
525:                    if (gp instanceof  JScrollPane) {
526:                        JScrollPane scrollPane = (JScrollPane) gp;
527:                        JViewport viewport = scrollPane.getViewport();
528:                        if (viewport == null || viewport.getView() != this )
529:                            return;
530:
531:                        configureScrollPaneHeaders(scrollPane);
532:
533:                        Border border = scrollPane.getBorder();
534:                        if (border == null || border instanceof  UIResource) {
535:                            scrollPane.setBorder(UIManager
536:                                    .getBorder("Table.scrollPaneBorder"));
537:                        }
538:                    }
539:                }
540:            }
541:
542:            public Node addNodeForImpl(Object impl) {
543:                return addNodeForImpl(impl, NodeModel.NORMAL);
544:            }
545:
546:            public Node addNodeForImpl(Object impl, int eventType) {
547:                int row = getCurrentRow();
548:                if (row == -1) { // fix for bug when inserting subproject and no selection
549:                    row = 0; // use 0th row if no selection
550:                    addRowSelectionInterval(0, 0);
551:                }
552:                Node current = getCurrentRowNode();
553:                Node newNode = NodeFactory.getInstance().createNode(impl);
554:                SpreadSheetModel model = (SpreadSheetModel) getModel();
555:                NodeModel nodeModel = model.getCache().getModel();
556:
557:                LinkedList previousNodes = model
558:                        .getPreviousVisibleNodesFromRow(row);
559:                if (previousNodes == null)
560:                    previousNodes = new LinkedList();
561:                previousNodes.add(current);
562:                nodeModel.addBefore(previousNodes, newNode, eventType);
563:                return newNode;
564:            }
565:
566:            public void graphicNodesCompositeEvent(
567:                    CompositeCacheEvent compositeEvent) {
568:                //System.out.println("cache event -> editCellAt");
569:                if (isEditing()) {
570:                    int row = getEditingRow();
571:                    int col = getEditingColumn();
572:                    TableCellEditor editor = getCellEditor();
573:                    editor.cancelCellEditing();
574:                    editCellAt(row, col);
575:                }
576:            }
577:
578:            public SpreadSheetRowHeader getRowHeader() {
579:                return rowHeader;
580:            }
581:
582:            public SpreadSheetCorner getCorner() {
583:                return corner;
584:            }
585:
586:            /**
587:             * For minor spreadsheets that have fixed columns, make sure they are not modifiable
588:             * @return
589:             */
590:            public final boolean isCanModifyColumns() {
591:                return canModifyColumns
592:                        && SpreadSheetUtils
593:                                .getFieldsForCategory(getSpreadSheetCategory()) != null;
594:            }
595:
596:            public final void setCanModifyColumns(boolean canModifyColumns) {
597:                this .canModifyColumns = canModifyColumns;
598:            }
599:
600:            public boolean isHasColumnHeaderPopup() {
601:                return isCanModifyColumns();
602:            }
603:
604:            public final boolean isCanSelectFieldArray() {
605:                return canSelectFieldArray;
606:            }
607:
608:            public final void setCanSelectFieldArray(boolean canSelectFieldArray) {
609:                this .canSelectFieldArray = canSelectFieldArray;
610:            }
611:
612:            public void resizeAndRepaintHeader() { // this is really abstract
613:            }
614:
615:            protected Exception lastException;
616:
617:            public final Exception getLastException() {
618:                return lastException;
619:            }
620:
621:            protected void doPostExceptionTreatment() {
622:
623:            }
624:
625:            public void setValueAt(Object arg0, int arg1, int arg2) {
626:                lastException = null; // initialize. will get set if a throw
627:                try {
628:                    super .setValueAt(arg0, arg1, arg2);
629:                } catch (Exception e) { // because setValue has no exceptions, I package it in a runtime one
630:                    lastException = (Exception) e.getCause(); // editors will use this value to see if exception
631:                    if (lastException == null)
632:                        lastException = e;
633:                    //FieldParseException parseException = (FieldParseException) lastException;
634:                    //ErrorLogger.log("setValueAt",lastException); //TODO clean up messages
635:                    doPostExceptionTreatment();
636:                }
637:            }
638:
639:            public void restoreWorkspace(WorkspaceSetting w, int context) {
640:                // this checks for invalid conditions and continues
641:
642:                Workspace ws = (Workspace) w;
643:                if (getRowCount() > ws.editingRow)
644:                    setEditingRow(ws.editingRow);
645:                if (getColumnCount() > ws.editingColumn)
646:                    setEditingColumn(ws.editingColumn);
647:                if (getRowCount() > ws.lastEditingRow)
648:                    lastEditingRow = ws.lastEditingRow;
649:                if (ws.selectedRows != null) {
650:                    for (int i = 0; i < ws.selectedRows.length; i++) {
651:                        try {
652:                            addRowSelectionInterval(ws.selectedRows[i],
653:                                    ws.selectedRows[i]);
654:                            // this isn't quite right.
655:                            rowHeader.addRowSelectionInterval(
656:                                    ws.selectedRows[i], ws.selectedRows[i]);
657:
658:                        } catch (RuntimeException e) {
659:                            // in case out of bounds
660:                        }
661:                    }
662:                }
663:                if (ws.selectedColumns != null) {
664:                    for (int i = 0; i < ws.selectedColumns.length; i++) {
665:                        try {
666:                            addColumnSelectionInterval(ws.selectedColumns[i],
667:                                    ws.selectedColumns[i]);
668:                        } catch (RuntimeException e) {
669:                            // in case out of bounds
670:                        }
671:                    }
672:                }
673:                //TODO the column widths are not set, so if they change, they are not used
674:                SpreadSheetFieldArray s = (SpreadSheetFieldArray) Dictionary
675:                        .get(getSpreadSheetCategory(), ws.fieldArrayName);
676:                if (s != null)
677:                    setFieldArray(s);
678:                Container p = getParent();
679:                if (p instanceof  JViewport && ws.viewPosition != null) {
680:                    try {
681:                        ((JViewport) p).setViewPosition(ws.viewPosition);
682:                    } catch (RuntimeException e) {
683:                        System.out
684:                                .println("problem restoring viewport to point "
685:                                        + ws.viewPosition);
686:                    }
687:                }
688:            }
689:
690:            public WorkspaceSetting createWorkspace(int context) {
691:                Workspace ws = new Workspace();
692:                ws.editingRow = getEditingRow();
693:                ws.editingColumn = getEditingColumn();
694:                ws.lastEditingRow = lastEditingRow;
695:                ws.selectedRows = getSelectedRows();
696:                ws.selectedColumns = getSelectedColumns();
697:                ws.fieldArrayName = getFieldArray().toString();
698:                Container p = getParent();
699:                if (p instanceof  JViewport) {
700:                    ws.viewPosition = ((JViewport) p).getViewPosition();
701:                }
702:                return ws;
703:            }
704:
705:            public static class Workspace implements  WorkspaceSetting {
706:                private static final long serialVersionUID = -847570793053006783L;
707:                //TODO the column sizes and possible reording aren't saved yet. maybe the easiest way would be to just serialize the column model. 
708:                int editingRow;
709:                int editingColumn;
710:                int lastEditingRow;
711:                int[] selectedRows = null;
712:                int[] selectedColumns = null;
713:                String fieldArrayName;
714:                Point viewPosition = null;
715:
716:                public final int getEditingColumn() {
717:                    return editingColumn;
718:                }
719:
720:                public final void setEditingColumn(int editingColumn) {
721:                    this .editingColumn = editingColumn;
722:                }
723:
724:                public final int getEditingRow() {
725:                    return editingRow;
726:                }
727:
728:                public final void setEditingRow(int editingRow) {
729:                    this .editingRow = editingRow;
730:                }
731:
732:                public final String getFieldArrayName() {
733:                    return fieldArrayName;
734:                }
735:
736:                public final void setFieldArrayName(String fieldArrayName) {
737:                    this .fieldArrayName = fieldArrayName;
738:                }
739:
740:                public final int getLastEditingRow() {
741:                    return lastEditingRow;
742:                }
743:
744:                public final void setLastEditingRow(int lastEditingRow) {
745:                    this .lastEditingRow = lastEditingRow;
746:                }
747:
748:                public final int[] getSelectedColumns() {
749:                    return selectedColumns;
750:                }
751:
752:                public final void setSelectedColumns(int[] selectedColumns) {
753:                    this .selectedColumns = selectedColumns;
754:                }
755:
756:                public final int[] getSelectedRows() {
757:                    return selectedRows;
758:                }
759:
760:                public final void setSelectedRows(int[] selectedRows) {
761:                    this .selectedRows = selectedRows;
762:                }
763:
764:                public Point getViewPosition() {
765:                    return viewPosition;
766:                }
767:
768:                public void setViewPosition(Point viewPosition) {
769:                    this.viewPosition = viewPosition;
770:                }
771:            }
772:
773:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.