Source Code Cross Referenced for CellEditorActionHandler.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » part » 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 » IDE Eclipse » ui workbench » org.eclipse.ui.part 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.part;
011:
012:        import java.util.HashMap;
013:        import java.util.Iterator;
014:
015:        import org.eclipse.core.runtime.Assert;
016:        import org.eclipse.jface.action.Action;
017:        import org.eclipse.jface.action.IAction;
018:        import org.eclipse.jface.util.IPropertyChangeListener;
019:        import org.eclipse.jface.util.PropertyChangeEvent;
020:        import org.eclipse.jface.viewers.CellEditor;
021:        import org.eclipse.swt.SWT;
022:        import org.eclipse.swt.widgets.Control;
023:        import org.eclipse.swt.widgets.Event;
024:        import org.eclipse.swt.widgets.Listener;
025:        import org.eclipse.ui.IActionBars;
026:        import org.eclipse.ui.PlatformUI;
027:        import org.eclipse.ui.actions.ActionFactory;
028:        import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
029:        import org.eclipse.ui.internal.WorkbenchMessages;
030:
031:        /**
032:         * Handles the redirection of the global actions Cut, Copy, Paste,
033:         * Delete, Select All, Find, Undo and Redo to either the current
034:         * inline cell editor or the part's supplied action handler.
035:         * <p>
036:         * This class may be instantiated; it is not intended to be subclassed.
037:         * </p><p>
038:         * Example usage:
039:         * <pre>
040:         * actionHandler = new CellEditorActionHandler(this.getViewSite().getActionBars());
041:         * actionHandler.addCellEditor(textCellEditor1);
042:         * actionHandler.addCellEditor(textCellEditor2);
043:         * actionHandler.setSelectAllAction(selectAllAction);
044:         * </pre>
045:         * </p>
046:         */
047:        public class CellEditorActionHandler {
048:            private CutActionHandler cellCutAction = new CutActionHandler();
049:
050:            private CopyActionHandler cellCopyAction = new CopyActionHandler();
051:
052:            private PasteActionHandler cellPasteAction = new PasteActionHandler();
053:
054:            private DeleteActionHandler cellDeleteAction = new DeleteActionHandler();
055:
056:            private SelectAllActionHandler cellSelectAllAction = new SelectAllActionHandler();
057:
058:            private FindActionHandler cellFindAction = new FindActionHandler();
059:
060:            private UndoActionHandler cellUndoAction = new UndoActionHandler();
061:
062:            private RedoActionHandler cellRedoAction = new RedoActionHandler();
063:
064:            private IAction cutAction;
065:
066:            private IAction copyAction;
067:
068:            private IAction pasteAction;
069:
070:            private IAction deleteAction;
071:
072:            private IAction selectAllAction;
073:
074:            private IAction findAction;
075:
076:            private IAction undoAction;
077:
078:            private IAction redoAction;
079:
080:            private IPropertyChangeListener cutActionListener = new ActionEnabledChangeListener(
081:                    cellCutAction);
082:
083:            private IPropertyChangeListener copyActionListener = new ActionEnabledChangeListener(
084:                    cellCopyAction);
085:
086:            private IPropertyChangeListener pasteActionListener = new ActionEnabledChangeListener(
087:                    cellPasteAction);
088:
089:            private IPropertyChangeListener deleteActionListener = new ActionEnabledChangeListener(
090:                    cellDeleteAction);
091:
092:            private IPropertyChangeListener selectAllActionListener = new ActionEnabledChangeListener(
093:                    cellSelectAllAction);
094:
095:            private IPropertyChangeListener findActionListener = new ActionEnabledChangeListener(
096:                    cellFindAction);
097:
098:            private IPropertyChangeListener undoActionListener = new ActionEnabledChangeListener(
099:                    cellUndoAction);
100:
101:            private IPropertyChangeListener redoActionListener = new ActionEnabledChangeListener(
102:                    cellRedoAction);
103:
104:            private CellEditor activeEditor;
105:
106:            private IPropertyChangeListener cellListener = new CellChangeListener();
107:
108:            private Listener controlListener = new ControlListener();
109:
110:            private HashMap controlToEditor = new HashMap();
111:
112:            private class ControlListener implements  Listener {
113:                public void handleEvent(Event event) {
114:                    switch (event.type) {
115:                    case SWT.Activate:
116:                        activeEditor = (CellEditor) controlToEditor
117:                                .get(event.widget);
118:                        if (activeEditor != null) {
119:                            activeEditor
120:                                    .addPropertyChangeListener(cellListener);
121:                        }
122:                        updateActionsEnableState();
123:                        break;
124:                    case SWT.Deactivate:
125:                        if (activeEditor != null) {
126:                            activeEditor
127:                                    .removePropertyChangeListener(cellListener);
128:                        }
129:                        activeEditor = null;
130:                        updateActionsEnableState();
131:                        break;
132:                    default:
133:                        break;
134:                    }
135:                }
136:            }
137:
138:            private class ActionEnabledChangeListener implements 
139:                    IPropertyChangeListener {
140:                private IAction actionHandler;
141:
142:                protected ActionEnabledChangeListener(IAction actionHandler) {
143:                    super ();
144:                    this .actionHandler = actionHandler;
145:                }
146:
147:                public void propertyChange(PropertyChangeEvent event) {
148:                    if (activeEditor != null) {
149:                        return;
150:                    }
151:                    if (event.getProperty().equals(IAction.ENABLED)) {
152:                        Boolean bool = (Boolean) event.getNewValue();
153:                        actionHandler.setEnabled(bool.booleanValue());
154:                        return;
155:                    }
156:                    // If the underlying action's text has changed, we need to
157:                    // change the text.  See
158:                    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=154410
159:                    if (event.getProperty().equals(IAction.TEXT)) {
160:                        String text = (String) event.getNewValue();
161:                        actionHandler.setText(text);
162:                        return;
163:                    }
164:                    if (event.getProperty().equals(IAction.TOOL_TIP_TEXT)) {
165:                        String text = (String) event.getNewValue();
166:                        actionHandler.setToolTipText(text);
167:                        return;
168:                    }
169:                }
170:            }
171:
172:            private class CellChangeListener implements  IPropertyChangeListener {
173:                public void propertyChange(PropertyChangeEvent event) {
174:                    if (activeEditor == null) {
175:                        return;
176:                    }
177:                    if (event.getProperty().equals(CellEditor.CUT)) {
178:                        cellCutAction.setEnabled(activeEditor.isCutEnabled());
179:                        return;
180:                    }
181:                    if (event.getProperty().equals(CellEditor.COPY)) {
182:                        cellCopyAction.setEnabled(activeEditor.isCopyEnabled());
183:                        return;
184:                    }
185:                    if (event.getProperty().equals(CellEditor.PASTE)) {
186:                        cellPasteAction.setEnabled(activeEditor
187:                                .isPasteEnabled());
188:                        return;
189:                    }
190:                    if (event.getProperty().equals(CellEditor.DELETE)) {
191:                        cellDeleteAction.setEnabled(activeEditor
192:                                .isDeleteEnabled());
193:                        return;
194:                    }
195:                    if (event.getProperty().equals(CellEditor.SELECT_ALL)) {
196:                        cellSelectAllAction.setEnabled(activeEditor
197:                                .isSelectAllEnabled());
198:                        return;
199:                    }
200:                    if (event.getProperty().equals(CellEditor.FIND)) {
201:                        cellFindAction.setEnabled(activeEditor.isFindEnabled());
202:                        return;
203:                    }
204:                    if (event.getProperty().equals(CellEditor.UNDO)) {
205:                        cellUndoAction.setEnabled(activeEditor.isUndoEnabled());
206:                        return;
207:                    }
208:                    if (event.getProperty().equals(CellEditor.REDO)) {
209:                        cellRedoAction.setEnabled(activeEditor.isRedoEnabled());
210:                        return;
211:                    }
212:                }
213:            }
214:
215:            private class CutActionHandler extends Action {
216:                protected CutActionHandler() {
217:                    setId("CellEditorCutActionHandler");//$NON-NLS-1$
218:                    setEnabled(false);
219:                    PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
220:                            IWorkbenchHelpContextIds.CELL_CUT_ACTION);
221:                }
222:
223:                public void runWithEvent(Event event) {
224:                    if (activeEditor != null) {
225:                        activeEditor.performCut();
226:                        return;
227:                    }
228:                    if (cutAction != null) {
229:                        cutAction.runWithEvent(event);
230:                        return;
231:                    }
232:                }
233:
234:                public void updateEnabledState() {
235:                    if (activeEditor != null) {
236:                        setEnabled(activeEditor.isCutEnabled());
237:                        return;
238:                    }
239:                    if (cutAction != null) {
240:                        setEnabled(cutAction.isEnabled());
241:                        return;
242:                    }
243:                    setEnabled(false);
244:                }
245:            }
246:
247:            private class CopyActionHandler extends Action {
248:                protected CopyActionHandler() {
249:                    setId("CellEditorCopyActionHandler");//$NON-NLS-1$
250:                    setEnabled(false);
251:                    PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
252:                            IWorkbenchHelpContextIds.CELL_COPY_ACTION);
253:                }
254:
255:                public void runWithEvent(Event event) {
256:                    if (activeEditor != null) {
257:                        activeEditor.performCopy();
258:                        return;
259:                    }
260:                    if (copyAction != null) {
261:                        copyAction.runWithEvent(event);
262:                        return;
263:                    }
264:                }
265:
266:                public void updateEnabledState() {
267:                    if (activeEditor != null) {
268:                        setEnabled(activeEditor.isCopyEnabled());
269:                        return;
270:                    }
271:                    if (copyAction != null) {
272:                        setEnabled(copyAction.isEnabled());
273:                        return;
274:                    }
275:                    setEnabled(false);
276:                }
277:            }
278:
279:            private class PasteActionHandler extends Action {
280:                protected PasteActionHandler() {
281:                    setId("CellEditorPasteActionHandler");//$NON-NLS-1$
282:                    setEnabled(false);
283:                    PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
284:                            IWorkbenchHelpContextIds.CELL_PASTE_ACTION);
285:                }
286:
287:                public void runWithEvent(Event event) {
288:                    if (activeEditor != null) {
289:                        activeEditor.performPaste();
290:                        return;
291:                    }
292:                    if (pasteAction != null) {
293:                        pasteAction.runWithEvent(event);
294:                        return;
295:                    }
296:                }
297:
298:                public void updateEnabledState() {
299:                    if (activeEditor != null) {
300:                        setEnabled(activeEditor.isPasteEnabled());
301:                        return;
302:                    }
303:                    if (pasteAction != null) {
304:                        setEnabled(pasteAction.isEnabled());
305:                        return;
306:                    }
307:                    setEnabled(false);
308:                }
309:            }
310:
311:            private class DeleteActionHandler extends Action {
312:                protected DeleteActionHandler() {
313:                    setId("CellEditorDeleteActionHandler");//$NON-NLS-1$
314:                    setEnabled(false);
315:                    PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
316:                            IWorkbenchHelpContextIds.CELL_DELETE_ACTION);
317:                }
318:
319:                public void runWithEvent(Event event) {
320:                    if (activeEditor != null) {
321:                        activeEditor.performDelete();
322:                        return;
323:                    }
324:                    if (deleteAction != null) {
325:                        deleteAction.runWithEvent(event);
326:                        return;
327:                    }
328:                }
329:
330:                public void updateEnabledState() {
331:                    if (activeEditor != null) {
332:                        setEnabled(activeEditor.isDeleteEnabled());
333:                        return;
334:                    }
335:                    if (deleteAction != null) {
336:                        setEnabled(deleteAction.isEnabled());
337:                        return;
338:                    }
339:                    setEnabled(false);
340:                }
341:            }
342:
343:            private class SelectAllActionHandler extends Action {
344:                protected SelectAllActionHandler() {
345:                    setId("CellEditorSelectAllActionHandler");//$NON-NLS-1$
346:                    setEnabled(false);
347:                    PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
348:                            IWorkbenchHelpContextIds.CELL_SELECT_ALL_ACTION);
349:                }
350:
351:                public void runWithEvent(Event event) {
352:                    if (activeEditor != null) {
353:                        activeEditor.performSelectAll();
354:                        return;
355:                    }
356:                    if (selectAllAction != null) {
357:                        selectAllAction.runWithEvent(event);
358:                        return;
359:                    }
360:                }
361:
362:                public void updateEnabledState() {
363:                    if (activeEditor != null) {
364:                        setEnabled(activeEditor.isSelectAllEnabled());
365:                        return;
366:                    }
367:                    if (selectAllAction != null) {
368:                        setEnabled(selectAllAction.isEnabled());
369:                        return;
370:                    }
371:                    setEnabled(false);
372:                }
373:            }
374:
375:            private class FindActionHandler extends Action {
376:                protected FindActionHandler() {
377:                    setId("CellEditorFindActionHandler");//$NON-NLS-1$
378:                    setEnabled(false);
379:                    PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
380:                            IWorkbenchHelpContextIds.CELL_FIND_ACTION);
381:                }
382:
383:                public void runWithEvent(Event event) {
384:                    if (activeEditor != null) {
385:                        activeEditor.performFind();
386:                        return;
387:                    }
388:                    if (findAction != null) {
389:                        findAction.runWithEvent(event);
390:                        return;
391:                    }
392:                }
393:
394:                public void updateEnabledState() {
395:                    if (activeEditor != null) {
396:                        setEnabled(activeEditor.isFindEnabled());
397:                        return;
398:                    }
399:                    if (findAction != null) {
400:                        setEnabled(findAction.isEnabled());
401:                        return;
402:                    }
403:                    setEnabled(false);
404:                }
405:            }
406:
407:            private class UndoActionHandler extends Action {
408:                protected UndoActionHandler() {
409:                    setId("CellEditorUndoActionHandler");//$NON-NLS-1$
410:                    setEnabled(false);
411:                    PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
412:                            IWorkbenchHelpContextIds.CELL_UNDO_ACTION);
413:                }
414:
415:                public void runWithEvent(Event event) {
416:                    if (activeEditor != null) {
417:                        activeEditor.performUndo();
418:                        return;
419:                    }
420:                    if (undoAction != null) {
421:                        undoAction.runWithEvent(event);
422:                        return;
423:                    }
424:                }
425:
426:                public void updateEnabledState() {
427:                    if (activeEditor != null) {
428:                        setEnabled(activeEditor.isUndoEnabled());
429:                        setText(WorkbenchMessages.Workbench_undo);
430:                        setToolTipText(WorkbenchMessages.Workbench_undoToolTip);
431:                        return;
432:                    }
433:                    if (undoAction != null) {
434:                        setEnabled(undoAction.isEnabled());
435:                        setText(undoAction.getText());
436:                        setToolTipText(undoAction.getToolTipText());
437:                        return;
438:                    }
439:                    setEnabled(false);
440:                }
441:            }
442:
443:            private class RedoActionHandler extends Action {
444:                protected RedoActionHandler() {
445:                    setId("CellEditorRedoActionHandler");//$NON-NLS-1$
446:                    setEnabled(false);
447:                    PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
448:                            IWorkbenchHelpContextIds.CELL_REDO_ACTION);
449:                }
450:
451:                public void runWithEvent(Event event) {
452:                    if (activeEditor != null) {
453:                        activeEditor.performRedo();
454:                        return;
455:                    }
456:                    if (redoAction != null) {
457:                        redoAction.runWithEvent(event);
458:                        return;
459:                    }
460:                }
461:
462:                public void updateEnabledState() {
463:                    if (activeEditor != null) {
464:                        setEnabled(activeEditor.isRedoEnabled());
465:                        setText(WorkbenchMessages.Workbench_redo);
466:                        setToolTipText(WorkbenchMessages.Workbench_redoToolTip);
467:                        return;
468:                    }
469:                    if (redoAction != null) {
470:                        setEnabled(redoAction.isEnabled());
471:                        setText(redoAction.getText());
472:                        setToolTipText(redoAction.getToolTipText());
473:                        return;
474:                    }
475:                    setEnabled(false);
476:                }
477:            }
478:
479:            /**
480:             * Creates a <code>CellEditor</code> action handler
481:             * for the global Cut, Copy, Paste, Delete, Select All,
482:             * Find, Undo, and Redo of the action bar.
483:             *
484:             * @param actionBar the action bar to register global
485:             *    action handlers.
486:             */
487:            public CellEditorActionHandler(IActionBars actionBar) {
488:                super ();
489:                actionBar.setGlobalActionHandler(ActionFactory.CUT.getId(),
490:                        cellCutAction);
491:                actionBar.setGlobalActionHandler(ActionFactory.COPY.getId(),
492:                        cellCopyAction);
493:                actionBar.setGlobalActionHandler(ActionFactory.PASTE.getId(),
494:                        cellPasteAction);
495:                actionBar.setGlobalActionHandler(ActionFactory.DELETE.getId(),
496:                        cellDeleteAction);
497:                actionBar.setGlobalActionHandler(ActionFactory.SELECT_ALL
498:                        .getId(), cellSelectAllAction);
499:                actionBar.setGlobalActionHandler(ActionFactory.FIND.getId(),
500:                        cellFindAction);
501:                actionBar.setGlobalActionHandler(ActionFactory.UNDO.getId(),
502:                        cellUndoAction);
503:                actionBar.setGlobalActionHandler(ActionFactory.REDO.getId(),
504:                        cellRedoAction);
505:            }
506:
507:            /**
508:             * Adds a <code>CellEditor</code> to the handler so that the
509:             * Cut, Copy, Paste, Delete, Select All, Find, Undo, and Redo
510:             * actions are redirected to it when active.
511:             *
512:             * @param editor the <code>CellEditor</code>
513:             */
514:            public void addCellEditor(CellEditor editor) {
515:                if (editor == null) {
516:                    return;
517:                }
518:
519:                Control control = editor.getControl();
520:                Assert.isNotNull(control);
521:                controlToEditor.put(control, editor);
522:                control.addListener(SWT.Activate, controlListener);
523:                control.addListener(SWT.Deactivate, controlListener);
524:
525:                if (control.isFocusControl()) {
526:                    activeEditor = editor;
527:                    editor.addPropertyChangeListener(cellListener);
528:                    updateActionsEnableState();
529:                }
530:            }
531:
532:            /**
533:             * Disposes of this action handler
534:             */
535:            public void dispose() {
536:                setCutAction(null);
537:                setCopyAction(null);
538:                setPasteAction(null);
539:                setDeleteAction(null);
540:                setSelectAllAction(null);
541:                setFindAction(null);
542:                setUndoAction(null);
543:                setRedoAction(null);
544:
545:                Iterator itr = controlToEditor.keySet().iterator();
546:                while (itr.hasNext()) {
547:                    Control control = (Control) itr.next();
548:                    if (!control.isDisposed()) {
549:                        control.removeListener(SWT.Activate, controlListener);
550:                        control.removeListener(SWT.Deactivate, controlListener);
551:                    }
552:                }
553:                controlToEditor.clear();
554:
555:                if (activeEditor != null) {
556:                    activeEditor.removePropertyChangeListener(cellListener);
557:                }
558:                activeEditor = null;
559:
560:            }
561:
562:            /**
563:             * Removes a <code>CellEditor</code> from the handler
564:             * so that the Cut, Copy, Paste, Delete, Select All, Find
565:             * Undo, and Redo actions are no longer redirected to it.
566:             *
567:             * @param editor the <code>CellEditor</code>
568:             */
569:            public void removeCellEditor(CellEditor editor) {
570:                if (editor == null) {
571:                    return;
572:                }
573:
574:                if (activeEditor == editor) {
575:                    activeEditor.removePropertyChangeListener(cellListener);
576:                    activeEditor = null;
577:                }
578:
579:                Control control = editor.getControl();
580:                if (control != null) {
581:                    controlToEditor.remove(control);
582:                    if (!control.isDisposed()) {
583:                        control.removeListener(SWT.Activate, controlListener);
584:                        control.removeListener(SWT.Deactivate, controlListener);
585:                    }
586:                }
587:            }
588:
589:            /**
590:             * Sets the default <code>IAction</code> handler for the Copy
591:             * action. This <code>IAction</code> is run only if no active
592:             * cell editor control.
593:             *
594:             * @param action the <code>IAction</code> to run for the
595:             *    Copy action, or <code>null</code> if not interested.
596:             */
597:            public void setCopyAction(IAction action) {
598:                if (copyAction == action) {
599:                    return;
600:                }
601:
602:                if (copyAction != null) {
603:                    copyAction.removePropertyChangeListener(copyActionListener);
604:                }
605:
606:                copyAction = action;
607:
608:                if (copyAction != null) {
609:                    copyAction.addPropertyChangeListener(copyActionListener);
610:                }
611:
612:                cellCopyAction.updateEnabledState();
613:            }
614:
615:            /**
616:             * Sets the default <code>IAction</code> handler for the Cut
617:             * action. This <code>IAction</code> is run only if no active
618:             * cell editor control.
619:             *
620:             * @param action the <code>IAction</code> to run for the
621:             *    Cut action, or <code>null</code> if not interested.
622:             */
623:            public void setCutAction(IAction action) {
624:                if (cutAction == action) {
625:                    return;
626:                }
627:
628:                if (cutAction != null) {
629:                    cutAction.removePropertyChangeListener(cutActionListener);
630:                }
631:
632:                cutAction = action;
633:
634:                if (cutAction != null) {
635:                    cutAction.addPropertyChangeListener(cutActionListener);
636:                }
637:
638:                cellCutAction.updateEnabledState();
639:            }
640:
641:            /**
642:             * Sets the default <code>IAction</code> handler for the Delete
643:             * action. This <code>IAction</code> is run only if no active
644:             * cell editor control.
645:             *
646:             * @param action the <code>IAction</code> to run for the
647:             *    Delete action, or <code>null</code> if not interested.
648:             */
649:            public void setDeleteAction(IAction action) {
650:                if (deleteAction == action) {
651:                    return;
652:                }
653:
654:                if (deleteAction != null) {
655:                    deleteAction
656:                            .removePropertyChangeListener(deleteActionListener);
657:                }
658:
659:                deleteAction = action;
660:
661:                if (deleteAction != null) {
662:                    deleteAction
663:                            .addPropertyChangeListener(deleteActionListener);
664:                }
665:
666:                cellDeleteAction.updateEnabledState();
667:            }
668:
669:            /**
670:             * Sets the default <code>IAction</code> handler for the Find
671:             * action. This <code>IAction</code> is run only if no active
672:             * cell editor control.
673:             *
674:             * @param action the <code>IAction</code> to run for the
675:             *    Find action, or <code>null</code> if not interested.
676:             */
677:            public void setFindAction(IAction action) {
678:                if (findAction == action) {
679:                    return;
680:                }
681:
682:                if (findAction != null) {
683:                    findAction.removePropertyChangeListener(findActionListener);
684:                }
685:
686:                findAction = action;
687:
688:                if (findAction != null) {
689:                    findAction.addPropertyChangeListener(findActionListener);
690:                }
691:
692:                cellFindAction.updateEnabledState();
693:            }
694:
695:            /**
696:             * Sets the default <code>IAction</code> handler for the Paste
697:             * action. This <code>IAction</code> is run only if no active
698:             * cell editor control.
699:             *
700:             * @param action the <code>IAction</code> to run for the
701:             *    Paste action, or <code>null</code> if not interested.
702:             */
703:            public void setPasteAction(IAction action) {
704:                if (pasteAction == action) {
705:                    return;
706:                }
707:
708:                if (pasteAction != null) {
709:                    pasteAction
710:                            .removePropertyChangeListener(pasteActionListener);
711:                }
712:
713:                pasteAction = action;
714:
715:                if (pasteAction != null) {
716:                    pasteAction.addPropertyChangeListener(pasteActionListener);
717:                }
718:
719:                cellPasteAction.updateEnabledState();
720:            }
721:
722:            /**
723:             * Sets the default <code>IAction</code> handler for the Redo
724:             * action. This <code>IAction</code> is run only if no active
725:             * cell editor control.
726:             *
727:             * @param action the <code>IAction</code> to run for the
728:             *    Redo action, or <code>null</code> if not interested.
729:             */
730:            public void setRedoAction(IAction action) {
731:                if (redoAction == action) {
732:                    return;
733:                }
734:
735:                if (redoAction != null) {
736:                    redoAction.removePropertyChangeListener(redoActionListener);
737:                }
738:
739:                redoAction = action;
740:
741:                if (redoAction != null) {
742:                    redoAction.addPropertyChangeListener(redoActionListener);
743:                }
744:
745:                cellRedoAction.updateEnabledState();
746:            }
747:
748:            /**
749:             * Sets the default <code>IAction</code> handler for the Select All
750:             * action. This <code>IAction</code> is run only if no active
751:             * cell editor control.
752:             *
753:             * @param action the <code>IAction</code> to run for the
754:             *    Select All action, or <code>null</code> if not interested.
755:             */
756:            public void setSelectAllAction(IAction action) {
757:                if (selectAllAction == action) {
758:                    return;
759:                }
760:
761:                if (selectAllAction != null) {
762:                    selectAllAction
763:                            .removePropertyChangeListener(selectAllActionListener);
764:                }
765:
766:                selectAllAction = action;
767:
768:                if (selectAllAction != null) {
769:                    selectAllAction
770:                            .addPropertyChangeListener(selectAllActionListener);
771:                }
772:
773:                cellSelectAllAction.updateEnabledState();
774:            }
775:
776:            /**
777:             * Sets the default <code>IAction</code> handler for the Undo
778:             * action. This <code>IAction</code> is run only if no active
779:             * cell editor control.
780:             *
781:             * @param action the <code>IAction</code> to run for the
782:             *    Undo action, or <code>null</code> if not interested.
783:             */
784:            public void setUndoAction(IAction action) {
785:                if (undoAction == action) {
786:                    return;
787:                }
788:
789:                if (undoAction != null) {
790:                    undoAction.removePropertyChangeListener(undoActionListener);
791:                }
792:
793:                undoAction = action;
794:
795:                if (undoAction != null) {
796:                    undoAction.addPropertyChangeListener(undoActionListener);
797:                }
798:
799:                cellUndoAction.updateEnabledState();
800:            }
801:
802:            /**
803:             * Updates the enable state of the Cut, Copy,
804:             * Paste, Delete, Select All, Find, Undo, and
805:             * Redo action handlers
806:             */
807:            private void updateActionsEnableState() {
808:                cellCutAction.updateEnabledState();
809:                cellCopyAction.updateEnabledState();
810:                cellPasteAction.updateEnabledState();
811:                cellDeleteAction.updateEnabledState();
812:                cellSelectAllAction.updateEnabledState();
813:                cellFindAction.updateEnabledState();
814:                cellUndoAction.updateEnabledState();
815:                cellRedoAction.updateEnabledState();
816:            }
817:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.