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


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2007 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.internal.console;
011:
012:        import java.util.ArrayList;
013:        import java.util.HashMap;
014:        import java.util.List;
015:        import java.util.Map;
016:
017:        import org.eclipse.core.runtime.ISafeRunnable;
018:        import org.eclipse.core.runtime.ListenerList;
019:        import org.eclipse.core.runtime.SafeRunner;
020:        import org.eclipse.jface.action.IToolBarManager;
021:        import org.eclipse.jface.action.Separator;
022:        import org.eclipse.jface.util.IPropertyChangeListener;
023:        import org.eclipse.jface.util.PropertyChangeEvent;
024:        import org.eclipse.jface.viewers.IBasicPropertyConstants;
025:        import org.eclipse.swt.widgets.Composite;
026:        import org.eclipse.ui.IPartListener2;
027:        import org.eclipse.ui.IViewReference;
028:        import org.eclipse.ui.IViewSite;
029:        import org.eclipse.ui.IWorkbenchPart;
030:        import org.eclipse.ui.IWorkbenchPartReference;
031:        import org.eclipse.ui.PlatformUI;
032:        import org.eclipse.ui.console.AbstractConsole;
033:        import org.eclipse.ui.console.ConsolePlugin;
034:        import org.eclipse.ui.console.IConsole;
035:        import org.eclipse.ui.console.IConsoleConstants;
036:        import org.eclipse.ui.console.IConsoleListener;
037:        import org.eclipse.ui.console.IConsoleManager;
038:        import org.eclipse.ui.console.IConsolePageParticipant;
039:        import org.eclipse.ui.console.IConsoleView;
040:        import org.eclipse.ui.part.IPage;
041:        import org.eclipse.ui.part.IPageBookViewPage;
042:        import org.eclipse.ui.part.MessagePage;
043:        import org.eclipse.ui.part.PageBook;
044:        import org.eclipse.ui.part.PageBookView;
045:        import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
046:
047:        /**
048:         * Page book console view.
049:         * 
050:         * @since 3.0
051:         */
052:        public class ConsoleView extends PageBookView implements  IConsoleView,
053:                IConsoleListener, IPropertyChangeListener, IPartListener2 {
054:
055:            /**
056:             * Whether this console is pinned.
057:             */
058:            private boolean fPinned = false;
059:
060:            /**
061:             * Stack of consoles in MRU order
062:             */
063:            private List fStack = new ArrayList();
064:
065:            /**
066:             * The console being displayed, or <code>null</code> if none
067:             */
068:            private IConsole fActiveConsole = null;
069:
070:            /**
071:             * Map of consoles to dummy console parts (used to close pages)
072:             */
073:            private Map fConsoleToPart;
074:
075:            /**
076:             * Map of consoles to array of page participants
077:             */
078:            private Map fConsoleToPageParticipants;
079:
080:            /**
081:             * Map of parts to consoles
082:             */
083:            private Map fPartToConsole;
084:
085:            /**
086:             * Whether this view is active
087:             */
088:            private boolean fActive = false;
089:
090:            // actions
091:            private PinConsoleAction fPinAction = null;
092:            private ConsoleDropDownAction fDisplayConsoleAction = null;
093:
094:            private OpenConsoleAction fOpenConsoleAction = null;
095:
096:            private boolean fScrollLock;
097:
098:            private boolean isAvailable() {
099:                return getPageBook() != null && !getPageBook().isDisposed();
100:            }
101:
102:            /* (non-Javadoc)
103:             * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
104:             */
105:            public void propertyChange(PropertyChangeEvent event) {
106:                Object source = event.getSource();
107:                if (source instanceof  IConsole
108:                        && event.getProperty().equals(
109:                                IBasicPropertyConstants.P_TEXT)) {
110:                    if (source.equals(getConsole())) {
111:                        updateTitle();
112:                    }
113:                }
114:
115:            }
116:
117:            /* (non-Javadoc)
118:             * @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart)
119:             */
120:            public void partClosed(IWorkbenchPart part) {
121:                super .partClosed(part);
122:                fPinAction.update();
123:            }
124:
125:            /* (non-Javadoc)
126:             * @see org.eclipse.debug.internal.ui.console.IConsoleView#getConsole()
127:             */
128:            public IConsole getConsole() {
129:                return fActiveConsole;
130:            }
131:
132:            /* (non-Javadoc)
133:             * @see org.eclipse.ui.part.PageBookView#showPageRec(org.eclipse.ui.part.PageBookView.PageRec)
134:             */
135:            protected void showPageRec(PageRec pageRec) {
136:                // don't show the page when pinned, unless this is the first console to be added
137:                // or its the default page
138:                if (fActiveConsole != null && pageRec.page != getDefaultPage()
139:                        && fPinned && fConsoleToPart.size() > 1) {
140:                    IConsole console = (IConsole) fPartToConsole
141:                            .get(pageRec.part);
142:                    if (!fStack.contains(console)) {
143:                        fStack.add(console);
144:                    }
145:                    return;
146:                }
147:
148:                IConsole recConsole = (IConsole) fPartToConsole
149:                        .get(pageRec.part);
150:                if (recConsole != null && recConsole.equals(fActiveConsole)) {
151:                    return;
152:                }
153:
154:                super .showPageRec(pageRec);
155:                fActiveConsole = recConsole;
156:                IConsole tos = null;
157:                if (!fStack.isEmpty()) {
158:                    tos = (IConsole) fStack.get(0);
159:                }
160:                if (tos != null && !tos.equals(fActiveConsole)) {
161:                    deactivateParticipants(tos);
162:                }
163:                if (fActiveConsole != null && !fActiveConsole.equals(tos)) {
164:                    fStack.remove(fActiveConsole);
165:                    fStack.add(0, fActiveConsole);
166:                    activateParticipants(fActiveConsole);
167:                }
168:                updateTitle();
169:                updateHelp();
170:                // update console actions
171:                if (fPinAction != null) {
172:                    fPinAction.update();
173:                }
174:                IPage page = getCurrentPage();
175:                if (page instanceof  IOConsolePage) {
176:                    ((IOConsolePage) page).setAutoScroll(!fScrollLock);
177:                }
178:            }
179:
180:            /**
181:             * Activates the participants for the given console, if any.
182:             * 
183:             * @param console
184:             */
185:            private void activateParticipants(IConsole console) {
186:                // activate
187:                if (console != null && fActive) {
188:                    final ListenerList listeners = getParticipants(console);
189:                    if (listeners != null) {
190:                        Object[] participants = listeners.getListeners();
191:                        for (int i = 0; i < participants.length; i++) {
192:                            final IConsolePageParticipant participant = (IConsolePageParticipant) participants[i];
193:                            SafeRunner.run(new ISafeRunnable() {
194:                                public void run() throws Exception {
195:                                    participant.activated();
196:                                }
197:
198:                                public void handleException(Throwable exception) {
199:                                    ConsolePlugin.log(exception);
200:                                    listeners.remove(participant);
201:                                }
202:                            });
203:                        }
204:                    }
205:                }
206:            }
207:
208:            /**
209:             * Returns a stack of consoles in the view in MRU order.
210:             * 
211:             * @return a stack of consoles in the view in MRU order
212:             */
213:            protected List getConsoleStack() {
214:                return fStack;
215:            }
216:
217:            /**
218:             * Updates the view title based on the active console
219:             */
220:            protected void updateTitle() {
221:                IConsole console = getConsole();
222:                if (console == null) {
223:                    setContentDescription(ConsoleMessages.ConsoleView_0);
224:                } else {
225:                    String newName = console.getName();
226:                    String oldName = getContentDescription();
227:                    if (newName != null && !(newName.equals(oldName))) {
228:                        setContentDescription(console.getName());
229:                    }
230:                }
231:            }
232:
233:            protected void updateHelp() {
234:                IConsole console = getConsole();
235:                String helpContextId = null;
236:                if (console instanceof  AbstractConsole) {
237:                    AbstractConsole abs = (AbstractConsole) console;
238:                    helpContextId = abs.getHelpContextId();
239:                }
240:                if (helpContextId == null) {
241:                    helpContextId = IConsoleHelpContextIds.CONSOLE_VIEW;
242:                }
243:                PlatformUI.getWorkbench().getHelpSystem().setHelp(
244:                        getPageBook().getParent(), helpContextId);
245:            }
246:
247:            /* (non-Javadoc)
248:             * @see org.eclipse.ui.part.PageBookView#doDestroyPage(org.eclipse.ui.IWorkbenchPart, org.eclipse.ui.part.PageBookView.PageRec)
249:             */
250:            protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) {
251:                IConsole console = (IConsole) fPartToConsole.get(part);
252:
253:                // dispose page participants
254:                ListenerList listeners = (ListenerList) fConsoleToPageParticipants
255:                        .remove(console);
256:                if (listeners != null) {
257:                    Object[] participants = listeners.getListeners();
258:                    for (int i = 0; i < participants.length; i++) {
259:                        final IConsolePageParticipant participant = (IConsolePageParticipant) participants[i];
260:                        SafeRunner.run(new ISafeRunnable() {
261:                            public void run() throws Exception {
262:                                participant.dispose();
263:                            }
264:
265:                            public void handleException(Throwable exception) {
266:                                ConsolePlugin.log(exception);
267:                            }
268:                        });
269:                    }
270:                }
271:
272:                IPage page = pageRecord.page;
273:                page.dispose();
274:                pageRecord.dispose();
275:                console.removePropertyChangeListener(this );
276:
277:                // empty cross-reference cache
278:                fPartToConsole.remove(part);
279:                fConsoleToPart.remove(console);
280:                if (fPartToConsole.isEmpty()) {
281:                    fActiveConsole = null;
282:                }
283:
284:                // update console actions
285:                fPinAction.update();
286:            }
287:
288:            /**
289:             * Returns the page participants registered for the given console, or <code>null</code>
290:             * 
291:             * @param console
292:             * @return registered page participants or <code>null</code>
293:             */
294:            private ListenerList getParticipants(IConsole console) {
295:                return (ListenerList) fConsoleToPageParticipants.get(console);
296:            }
297:
298:            /* (non-Javadoc)
299:             * @see org.eclipse.ui.part.PageBookView#doCreatePage(org.eclipse.ui.IWorkbenchPart)
300:             */
301:            protected PageRec doCreatePage(IWorkbenchPart dummyPart) {
302:                ConsoleWorkbenchPart part = (ConsoleWorkbenchPart) dummyPart;
303:                final IConsole console = part.getConsole();
304:                final IPageBookViewPage page = console.createPage(this );
305:                initPage(page);
306:                page.createControl(getPageBook());
307:                console.addPropertyChangeListener(this );
308:
309:                // initialize page participants
310:                IConsolePageParticipant[] consoleParticipants = ((ConsoleManager) getConsoleManager())
311:                        .getPageParticipants(console);
312:                final ListenerList participants = new ListenerList();
313:                for (int i = 0; i < consoleParticipants.length; i++) {
314:                    participants.add(consoleParticipants[i]);
315:                }
316:                fConsoleToPageParticipants.put(console, participants);
317:                Object[] listeners = participants.getListeners();
318:                for (int i = 0; i < listeners.length; i++) {
319:                    final IConsolePageParticipant participant = (IConsolePageParticipant) listeners[i];
320:                    SafeRunner.run(new ISafeRunnable() {
321:                        public void run() throws Exception {
322:                            participant.init(page, console);
323:                        }
324:
325:                        public void handleException(Throwable exception) {
326:                            ConsolePlugin.log(exception);
327:                            participants.remove(participant);
328:                        }
329:                    });
330:                }
331:
332:                PageRec rec = new PageRec(dummyPart, page);
333:                return rec;
334:            }
335:
336:            /* (non-Javadoc)
337:             * @see org.eclipse.ui.part.PageBookView#isImportant(org.eclipse.ui.IWorkbenchPart)
338:             */
339:            protected boolean isImportant(IWorkbenchPart part) {
340:                return part instanceof  ConsoleWorkbenchPart;
341:            }
342:
343:            /* (non-Javadoc)
344:             * @see org.eclipse.ui.IWorkbenchPart#dispose()
345:             */
346:            public void dispose() {
347:                super .dispose();
348:                getViewSite().getPage().removePartListener(
349:                        (IPartListener2) this );
350:                ConsoleManager consoleManager = (ConsoleManager) ConsolePlugin
351:                        .getDefault().getConsoleManager();
352:                consoleManager.removeConsoleListener(this );
353:                consoleManager.unregisterConsoleView(this );
354:            }
355:
356:            /**
357:             * Returns the console manager.
358:             * 
359:             * @return the console manager
360:             */
361:            private IConsoleManager getConsoleManager() {
362:                return ConsolePlugin.getDefault().getConsoleManager();
363:            }
364:
365:            /* (non-Javadoc)
366:             * @see org.eclipse.ui.part.PageBookView#createDefaultPage(org.eclipse.ui.part.PageBook)
367:             */
368:            protected IPage createDefaultPage(PageBook book) {
369:                MessagePage page = new MessagePage();
370:                page.createControl(getPageBook());
371:                initPage(page);
372:                return page;
373:            }
374:
375:            /* (non-Javadoc)
376:             * @see org.eclipse.ui.console.IConsoleListener#consolesAdded(org.eclipse.ui.console.IConsole[])
377:             */
378:            public void consolesAdded(final IConsole[] consoles) {
379:                if (isAvailable()) {
380:                    Runnable r = new Runnable() {
381:                        public void run() {
382:                            for (int i = 0; i < consoles.length; i++) {
383:                                if (isAvailable()) {
384:                                    IConsole console = consoles[i];
385:                                    // ensure it's still registered since this is done asynchronously
386:                                    IConsole[] allConsoles = getConsoleManager()
387:                                            .getConsoles();
388:                                    for (int j = 0; j < allConsoles.length; j++) {
389:                                        IConsole registered = allConsoles[j];
390:                                        if (registered.equals(console)) {
391:                                            ConsoleWorkbenchPart part = new ConsoleWorkbenchPart(
392:                                                    console, getSite());
393:                                            fConsoleToPart.put(console, part);
394:                                            fPartToConsole.put(part, console);
395:                                            partActivated(part);
396:                                            break;
397:                                        }
398:                                    }
399:
400:                                }
401:                            }
402:                        }
403:                    };
404:                    asyncExec(r);
405:                }
406:            }
407:
408:            /* (non-Javadoc)
409:             * @see org.eclipse.ui.console.IConsoleListener#consolesRemoved(org.eclipse.ui.console.IConsole[])
410:             */
411:            public void consolesRemoved(final IConsole[] consoles) {
412:                if (isAvailable()) {
413:                    Runnable r = new Runnable() {
414:                        public void run() {
415:                            for (int i = 0; i < consoles.length; i++) {
416:                                if (isAvailable()) {
417:                                    IConsole console = consoles[i];
418:                                    fStack.remove(console);
419:                                    ConsoleWorkbenchPart part = (ConsoleWorkbenchPart) fConsoleToPart
420:                                            .get(console);
421:                                    if (part != null) {
422:                                        partClosed(part);
423:                                    }
424:                                    if (getConsole() == null) {
425:                                        IConsole[] available = getConsoleManager()
426:                                                .getConsoles();
427:                                        if (available.length > 0) {
428:                                            display(available[available.length - 1]);
429:                                        }
430:                                    }
431:                                }
432:                            }
433:                        }
434:                    };
435:                    asyncExec(r);
436:                }
437:            }
438:
439:            /**
440:             * Constructs a console view
441:             */
442:            public ConsoleView() {
443:                super ();
444:                fConsoleToPart = new HashMap();
445:                fPartToConsole = new HashMap();
446:                fConsoleToPageParticipants = new HashMap();
447:
448:                ConsoleManager consoleManager = (ConsoleManager) ConsolePlugin
449:                        .getDefault().getConsoleManager();
450:                consoleManager.registerConsoleView(this );
451:            }
452:
453:            protected void createActions() {
454:                fPinAction = new PinConsoleAction(this );
455:                fDisplayConsoleAction = new ConsoleDropDownAction(this );
456:                ConsoleFactoryExtension[] extensions = ((ConsoleManager) ConsolePlugin
457:                        .getDefault().getConsoleManager())
458:                        .getConsoleFactoryExtensions();
459:                if (extensions.length > 0) {
460:                    fOpenConsoleAction = new OpenConsoleAction();
461:                }
462:            }
463:
464:            protected void configureToolBar(IToolBarManager mgr) {
465:                mgr.add(new Separator(IConsoleConstants.LAUNCH_GROUP));
466:                mgr.add(new Separator(IConsoleConstants.OUTPUT_GROUP));
467:                mgr.add(new Separator("fixedGroup")); //$NON-NLS-1$
468:                mgr.add(fPinAction);
469:                mgr.add(fDisplayConsoleAction);
470:                if (fOpenConsoleAction != null) {
471:                    mgr.add(fOpenConsoleAction);
472:                }
473:            }
474:
475:            /* (non-Javadoc)
476:             * @see org.eclipse.ui.console.IConsoleView#display(org.eclipse.ui.console.IConsole)
477:             */
478:            public void display(IConsole console) {
479:                if (fPinned && fActiveConsole != null) {
480:                    return;
481:                }
482:                if (console.equals(fActiveConsole)) {
483:                    return;
484:                }
485:                ConsoleWorkbenchPart part = (ConsoleWorkbenchPart) fConsoleToPart
486:                        .get(console);
487:                if (part != null) {
488:                    partActivated(part);
489:                }
490:            }
491:
492:            /*/* (non-Javadoc)
493:             * @see org.eclipse.ui.console.IConsoleView#pin(org.eclipse.ui.console.IConsole)
494:             */
495:            public void setPinned(boolean pin) {
496:                fPinned = pin;
497:                if (fPinAction != null) {
498:                    fPinAction.update();
499:                }
500:            }
501:
502:            /* (non-Javadoc)
503:             * @see org.eclipse.ui.console.IConsoleView#isPinned()
504:             */
505:            public boolean isPinned() {
506:                return fPinned;
507:            }
508:
509:            /* (non-Javadoc)
510:             * @see org.eclipse.ui.part.PageBookView#getBootstrapPart()
511:             */
512:            protected IWorkbenchPart getBootstrapPart() {
513:                return null;
514:            }
515:
516:            /**
517:             * Registers the given runnable with the display
518:             * associated with this view's control, if any.
519:             * 
520:             * @see org.eclipse.swt.widgets.Display#asyncExec(java.lang.Runnable)
521:             */
522:            public void asyncExec(Runnable r) {
523:                if (isAvailable()) {
524:                    getPageBook().getDisplay().asyncExec(r);
525:                }
526:            }
527:
528:            /**
529:             * Creates this view's underlying viewer and actions.
530:             * Hooks a pop-up menu to the underlying viewer's control,
531:             * as well as a key listener. When the delete key is pressed,
532:             * the <code>REMOVE_ACTION</code> is invoked. Hooks help to
533:             * this view. Subclasses must implement the following methods
534:             * which are called in the following order when a view is
535:             * created:<ul>
536:             * <li><code>createViewer(Composite)</code> - the context
537:             *   menu is hooked to the viewer's control.</li>
538:             * <li><code>createActions()</code></li>
539:             * <li><code>configureToolBar(IToolBarManager)</code></li>
540:             * <li><code>getHelpContextId()</code></li>
541:             * </ul>
542:             * @see IWorkbenchPart#createPartControl(Composite)
543:             */
544:            public void createPartControl(Composite parent) {
545:                super .createPartControl(parent);
546:                createActions();
547:                IToolBarManager tbm = getViewSite().getActionBars()
548:                        .getToolBarManager();
549:                configureToolBar(tbm);
550:                updateForExistingConsoles();
551:                getViewSite().getActionBars().updateActionBars();
552:                PlatformUI.getWorkbench().getHelpSystem().setHelp(parent,
553:                        IConsoleHelpContextIds.CONSOLE_VIEW);
554:                getViewSite().getPage().addPartListener((IPartListener2) this );
555:            }
556:
557:            /**
558:             * Initialize for existing consoles
559:             */
560:            private void updateForExistingConsoles() {
561:                IConsoleManager manager = getConsoleManager();
562:                // create pages for consoles
563:                IConsole[] consoles = manager.getConsoles();
564:                consolesAdded(consoles);
565:                // add as a listener
566:                manager.addConsoleListener(this );
567:            }
568:
569:            /* (non-Javadoc)
570:             * @see org.eclipse.ui.console.IConsoleView#warnOfContentChange(org.eclipse.ui.console.IConsole)
571:             */
572:            public void warnOfContentChange(IConsole console) {
573:                IWorkbenchPart part = (IWorkbenchPart) fConsoleToPart
574:                        .get(console);
575:                if (part != null) {
576:                    IWorkbenchSiteProgressService service = (IWorkbenchSiteProgressService) part
577:                            .getSite().getAdapter(
578:                                    IWorkbenchSiteProgressService.class);
579:                    if (service != null) {
580:                        service.warnOfContentChange();
581:                    }
582:                }
583:            }
584:
585:            public Object getAdapter(Class key) {
586:                Object adpater = super .getAdapter(key);
587:                if (adpater == null) {
588:                    IConsole console = getConsole();
589:                    if (console != null) {
590:                        ListenerList listeners = getParticipants(console);
591:                        // an adapter can be asked for before the console participants are created
592:                        if (listeners != null) {
593:                            Object[] participants = listeners.getListeners();
594:                            for (int i = 0; i < participants.length; i++) {
595:                                IConsolePageParticipant participant = (IConsolePageParticipant) participants[i];
596:                                adpater = participant.getAdapter(key);
597:                                if (adpater != null) {
598:                                    return adpater;
599:                                }
600:                            }
601:                        }
602:                    }
603:                }
604:                return adpater;
605:            }
606:
607:            /* (non-Javadoc)
608:             * @see org.eclipse.ui.IPartListener2#partActivated(org.eclipse.ui.IWorkbenchPartReference)
609:             */
610:            public void partActivated(IWorkbenchPartReference partRef) {
611:                if (isThisPart(partRef)) {
612:                    fActive = true;
613:                    activateParticipants(fActiveConsole);
614:                }
615:            }
616:
617:            /* (non-Javadoc)
618:             * @see org.eclipse.ui.IPartListener2#partBroughtToTop(org.eclipse.ui.IWorkbenchPartReference)
619:             */
620:            public void partBroughtToTop(IWorkbenchPartReference partRef) {
621:            }
622:
623:            /* (non-Javadoc)
624:             * @see org.eclipse.ui.IPartListener2#partClosed(org.eclipse.ui.IWorkbenchPartReference)
625:             */
626:            public void partClosed(IWorkbenchPartReference partRef) {
627:            }
628:
629:            /* (non-Javadoc)
630:             * @see org.eclipse.ui.IPartListener2#partDeactivated(org.eclipse.ui.IWorkbenchPartReference)
631:             */
632:            public void partDeactivated(IWorkbenchPartReference partRef) {
633:                if (isThisPart(partRef)) {
634:                    fActive = false;
635:                    deactivateParticipants(fActiveConsole);
636:                }
637:            }
638:
639:            protected boolean isThisPart(IWorkbenchPartReference partRef) {
640:                if (partRef instanceof  IViewReference) {
641:                    IViewReference viewRef = (IViewReference) partRef;
642:                    if (viewRef.getId().equals(getViewSite().getId())) {
643:                        String secId = viewRef.getSecondaryId();
644:                        String mySec = null;
645:                        if (getSite() instanceof  IViewSite) {
646:                            mySec = ((IViewSite) getSite()).getSecondaryId();
647:                        }
648:                        if (mySec == null) {
649:                            return secId == null;
650:                        }
651:                        return mySec.equals(secId);
652:                    }
653:                }
654:                return false;
655:            }
656:
657:            /**
658:             * Deactivates participants for the given console, if any.
659:             * 
660:             * @param console console to deactivate
661:             */
662:            private void deactivateParticipants(IConsole console) {
663:                // deactivate
664:                if (console != null) {
665:                    final ListenerList listeners = getParticipants(console);
666:                    if (listeners != null) {
667:                        Object[] participants = listeners.getListeners();
668:                        for (int i = 0; i < participants.length; i++) {
669:                            final IConsolePageParticipant participant = (IConsolePageParticipant) participants[i];
670:                            SafeRunner.run(new ISafeRunnable() {
671:                                public void run() throws Exception {
672:                                    participant.deactivated();
673:                                }
674:
675:                                public void handleException(Throwable exception) {
676:                                    ConsolePlugin.log(exception);
677:                                    listeners.remove(participant);
678:                                }
679:                            });
680:                        }
681:                    }
682:                }
683:            }
684:
685:            /* (non-Javadoc)
686:             * @see org.eclipse.ui.IPartListener2#partOpened(org.eclipse.ui.IWorkbenchPartReference)
687:             */
688:            public void partOpened(IWorkbenchPartReference partRef) {
689:            }
690:
691:            /* (non-Javadoc)
692:             * @see org.eclipse.ui.IPartListener2#partHidden(org.eclipse.ui.IWorkbenchPartReference)
693:             */
694:            public void partHidden(IWorkbenchPartReference partRef) {
695:            }
696:
697:            /* (non-Javadoc)
698:             * @see org.eclipse.ui.IPartListener2#partVisible(org.eclipse.ui.IWorkbenchPartReference)
699:             */
700:            public void partVisible(IWorkbenchPartReference partRef) {
701:            }
702:
703:            /* (non-Javadoc)
704:             * @see org.eclipse.ui.IPartListener2#partInputChanged(org.eclipse.ui.IWorkbenchPartReference)
705:             */
706:            public void partInputChanged(IWorkbenchPartReference partRef) {
707:            }
708:
709:            /* (non-Javadoc)
710:             * @see org.eclipse.ui.console.IConsoleView#setScrollLock(boolean)
711:             */
712:            public void setScrollLock(boolean scrollLock) {
713:                fScrollLock = scrollLock;
714:
715:                IPage page = getCurrentPage();
716:                if (page instanceof  IOConsolePage) {
717:                    ((IOConsolePage) page).setAutoScroll(!scrollLock);
718:                }
719:            }
720:
721:            /* (non-Javadoc)
722:             * @see org.eclipse.ui.console.IConsoleView#getScrollLock()
723:             */
724:            public boolean getScrollLock() {
725:                return fScrollLock;
726:            }
727:
728:            /* (non-Javadoc)
729:             * @see org.eclipse.ui.console.IConsoleView#pin(org.eclipse.ui.console.IConsole)
730:             */
731:            public void pin(IConsole console) {
732:                if (console == null) {
733:                    setPinned(false);
734:                } else {
735:                    if (isPinned()) {
736:                        setPinned(false);
737:                    }
738:                    display(console);
739:                    setPinned(true);
740:                }
741:            }
742:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.