Source Code Cross Referenced for ViewPane.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » 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.internal 
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:         *    Cagatay Kavukcuoglu <cagatayk@acm.org>
011:         *      - Fix for bug 10025 - Resizing views should not use height ratios
012:         *******************************************************************************/package org.eclipse.ui.internal;
013:
014:        import org.eclipse.jface.action.MenuManager;
015:        import org.eclipse.jface.internal.provisional.action.IToolBarManager2;
016:        import org.eclipse.jface.util.IPropertyChangeListener;
017:        import org.eclipse.jface.util.PropertyChangeEvent;
018:        import org.eclipse.swt.SWT;
019:        import org.eclipse.swt.events.MouseAdapter;
020:        import org.eclipse.swt.events.MouseEvent;
021:        import org.eclipse.swt.graphics.Point;
022:        import org.eclipse.swt.graphics.Rectangle;
023:        import org.eclipse.swt.widgets.Composite;
024:        import org.eclipse.swt.widgets.Control;
025:        import org.eclipse.swt.widgets.Menu;
026:        import org.eclipse.swt.widgets.Shell;
027:        import org.eclipse.swt.widgets.ToolBar;
028:        import org.eclipse.ui.IViewReference;
029:        import org.eclipse.ui.IWorkbenchPart;
030:        import org.eclipse.ui.internal.dnd.DragUtil;
031:        import org.eclipse.ui.internal.provisional.presentations.IActionBarPresentationFactory;
032:        import org.eclipse.ui.presentations.IPresentablePart;
033:        import org.eclipse.ui.presentations.StackPresentation;
034:
035:        /**
036:         * Provides a wrapper for the view's widgetry.
037:         * 
038:         * TODO: Delete ViewPane and EditorPane, and make PartPane non-abstract.
039:         */
040:        public class ViewPane extends PartPane {
041:
042:            // create initially toolbarless bar manager so that actions may be added in the 
043:            // init method of the view.
044:            private IToolBarManager2 isvToolBarMgr = null;
045:
046:            private MenuManager isvMenuMgr;
047:
048:            boolean hasFocus;
049:
050:            /**
051:             * Indicates whether a toolbar button is shown for the view local menu.
052:             */
053:            private boolean hadViewMenu = false;
054:
055:            /**
056:             * Toolbar manager for the ISV toolbar.
057:             */
058:            private class ISVPropListener implements  IPropertyChangeListener {
059:                private Control toolBar;
060:
061:                /**
062:                 * Constructor
063:                 * @param toolBar
064:                 */
065:                public ISVPropListener(Control toolBar) {
066:                    this .toolBar = toolBar;
067:                }
068:
069:                /* (non-Javadoc)
070:                 * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
071:                 */
072:                public void propertyChange(PropertyChangeEvent event) {
073:                    String property = event.getProperty();
074:                    Integer newValue = (Integer) event.getNewValue();
075:                    if (IToolBarManager2.PROP_LAYOUT.equals(property)) {
076:                        toolBarResized(toolBar, newValue != null ? newValue
077:                                .intValue() : 0);
078:                        if (toolBar instanceof  Composite) {
079:                            ((Composite) toolBar).layout();
080:                        } else {
081:                            toolBar.getParent().layout();
082:                        }
083:                    }
084:                }
085:            }
086:
087:            /**
088:             * Menu manager for view local menu.
089:             */
090:            class PaneMenuManager extends MenuManager {
091:                public PaneMenuManager() {
092:                    super ("View Local Menu"); //$NON-NLS-1$
093:                }
094:
095:                protected void update(boolean force, boolean recursive) {
096:                    super .update(force, recursive);
097:
098:                    boolean hasMenu = !isEmpty();
099:                    if (hasMenu != hadViewMenu) {
100:                        hadViewMenu = hasMenu;
101:                        firePropertyChange(IPresentablePart.PROP_PANE_MENU);
102:                    }
103:                }
104:            }
105:
106:            /**
107:             * Constructs a view pane for a view part.
108:             */
109:            public ViewPane(IViewReference ref, WorkbenchPage page) {
110:                super (ref, page);
111:                IActionBarPresentationFactory actionBarPresentation = ((WorkbenchWindow) page
112:                        .getWorkbenchWindow())
113:                        .getActionBarPresentationFactory();
114:
115:                isvToolBarMgr = actionBarPresentation
116:                        .createViewToolBarManager();
117:            }
118:
119:            /**
120:             * Create control. Add the title bar.
121:             */
122:            public void createControl(Composite parent) {
123:                // Only do this once.
124:                if (getControl() != null && !getControl().isDisposed()) {
125:                    return;
126:                }
127:
128:                super .createControl(parent);
129:            }
130:
131:            /**
132:             * Create a title bar for the pane.
133:             * 	- the view icon and title to the far left
134:             *	- the view toolbar appears in the middle.
135:             * 	- the view pulldown menu, pin button, and close button to the far right.
136:             */
137:            protected void createTitleBar() {
138:                // Only do this once.
139:
140:                updateTitles();
141:
142:                // Listen to title changes.
143:                getPartReference().addPropertyListener(this );
144:
145:                createToolBars();
146:
147:            }
148:
149:            private void toolBarResized(Control toolBar, int newSize) {
150:
151:                Control toolbar = isvToolBarMgr.getControl2();
152:                if (toolbar != null) {
153:                    Control ctrl = getControl();
154:
155:                    boolean visible = ctrl != null && ctrl.isVisible()
156:                            && toolbarIsVisible();
157:
158:                    toolbar.setVisible(visible);
159:                }
160:
161:                firePropertyChange(IPresentablePart.PROP_TOOLBAR);
162:            }
163:
164:            /**
165:             * 
166:             */
167:            private void createToolBars() {
168:                Composite parentControl = control;
169:
170:                // ISV toolbar.
171:                //			// 1GD0ISU: ITPUI:ALL - Dbl click on view tool cause zoom
172:                final Control isvToolBar = isvToolBarMgr
173:                        .createControl2(parentControl.getParent());
174:
175:                isvToolBarMgr.addPropertyChangeListener(new ISVPropListener(
176:                        isvToolBar));
177:
178:                isvToolBar.addMouseListener(new MouseAdapter() {
179:                    public void mouseDoubleClick(MouseEvent event) {
180:                        if (event.widget instanceof  ToolBar) {
181:
182:                            if (((ToolBar) event.widget).getItem(new Point(
183:                                    event.x, event.y)) == null) {
184:                                doZoom();
185:                            }
186:                        }
187:                    }
188:                });
189:
190:                isvToolBar.addListener(SWT.Activate, this );
191:                isvToolBar.moveAbove(control);
192:            }
193:
194:            public void dispose() {
195:                super .dispose();
196:
197:                /* Bug 42684.  The ViewPane instance has been disposed, but an attempt is
198:                 * then made to remove focus from it.  This happens because the ViewPane is
199:                 * still viewed as the active part.  In general, when disposed, the control
200:                 * containing the titleLabel will also disappear (disposing of the 
201:                 * titleLabel).  As a result, the reference to titleLabel should be dropped. 
202:                 */
203:                if (isvMenuMgr != null) {
204:                    isvMenuMgr.dispose();
205:                }
206:                if (isvToolBarMgr != null) {
207:                    isvToolBarMgr.dispose();
208:                }
209:            }
210:
211:            /**
212:             * @see PartPane#doHide
213:             */
214:            public void doHide() {
215:                getPage().hideView(getViewReference());
216:            }
217:
218:            /*package*/Rectangle getParentBounds() {
219:                Control ctrl = getControl();
220:
221:                if (getContainer() != null
222:                        && getContainer() instanceof  LayoutPart) {
223:                    LayoutPart part = (LayoutPart) getContainer();
224:
225:                    if (part.getControl() != null) {
226:                        ctrl = part.getControl();
227:                    }
228:                }
229:
230:                return DragUtil.getDisplayBounds(ctrl);
231:            }
232:
233:            /**
234:             * Make this view pane a fast view
235:             */
236:            public void doMakeFast() {
237:                WorkbenchWindow window = (WorkbenchWindow) getPage()
238:                        .getWorkbenchWindow();
239:
240:                FastViewBar fastViewBar = window.getFastViewBar();
241:                if (fastViewBar == null
242:                        || getPage().getActivePerspective() == null)
243:                    return;
244:
245:                Shell shell = window.getShell();
246:
247:                RectangleAnimation animation = new RectangleAnimation(shell,
248:                        getParentBounds(), fastViewBar.getLocationOfNextIcon());
249:
250:                animation.schedule();
251:
252:                FastViewManager fvm = getPage().getActivePerspective()
253:                        .getFastViewManager();
254:                fvm.addViewReference(FastViewBar.FASTVIEWBAR_ID, -1,
255:                        getViewReference(), true);
256:            }
257:
258:            public void doRemoveFast() {
259:                if (getPage().getActivePerspective() == null)
260:                    return;
261:
262:                Shell shell = getControl().getShell();
263:
264:                Rectangle initialBounds = getParentBounds();
265:
266:                FastViewManager fvm = getPage().getActivePerspective()
267:                        .getFastViewManager();
268:                fvm.removeViewReference(getViewReference(), true, true);
269:
270:                IWorkbenchPart toActivate = getViewReference().getPart(true);
271:                if (toActivate != null) {
272:                    getPage().activate(toActivate);
273:                }
274:
275:                Rectangle finalBounds = getParentBounds();
276:
277:                RectangleAnimation animation = new RectangleAnimation(shell,
278:                        initialBounds, finalBounds);
279:
280:                animation.schedule();
281:            }
282:
283:            /**
284:             * Pin the view.
285:             */
286:            protected void doDock() {
287:                Perspective persp = getPage().getActivePerspective();
288:                if (persp != null) {
289:                    persp.getFastViewManager().removeViewReference(
290:                            getViewReference(), true, true);
291:                }
292:            }
293:
294:            public void doDetach() {
295:                getPage().detachView(getViewReference());
296:            }
297:
298:            public void doAttach() {
299:                getPage().attachView(getViewReference());
300:            }
301:
302:            /* (non-Javadoc)
303:             * @see org.eclipse.ui.internal.LayoutPart#getCompoundId()
304:             */
305:            public String getCompoundId() {
306:                IViewReference ref = getViewReference();
307:                if (ref != null) {
308:                    return ViewFactory.getKey(ref);
309:                }
310:
311:                return super .getCompoundId();
312:            }
313:
314:            /**
315:             * Returns the drag control.
316:             */
317:            public Control getDragHandle() {
318:                return control;
319:            }
320:
321:            /**
322:             * @see ViewActionBars
323:             */
324:            public MenuManager getMenuManager() {
325:                if (isvMenuMgr == null) {
326:                    isvMenuMgr = new PaneMenuManager();
327:                }
328:                return isvMenuMgr;
329:            }
330:
331:            /**
332:             * Returns the tab list to use when this part is active.
333:             * Includes the view and its tab (if applicable), in the appropriate order.
334:             */
335:            public Control[] getTabList() {
336:                Control c = getControl();
337:                if (getContainer() instanceof  ViewStack) {
338:                    ViewStack tf = (ViewStack) getContainer();
339:                    return tf.getTabList(this );
340:                }
341:                return new Control[] { c };
342:            }
343:
344:            /**
345:             * @see ViewActionBars
346:             */
347:            public IToolBarManager2 getToolBarManager() {
348:                return isvToolBarMgr;
349:            }
350:
351:            /**
352:             * Answer the view part child.
353:             */
354:            public IViewReference getViewReference() {
355:                return (IViewReference) getPartReference();
356:            }
357:
358:            /**
359:             * Sets the fast view state.  If this view is a fast view then
360:             * various controls like pin and minimize are added to the
361:             * system bar.
362:             */
363:            public void setFast(boolean b) {
364:            }
365:
366:            /* (non-Javadoc)
367:             * Method declared on PartPane.
368:             */
369:            /* package */
370:            void shellActivated() {
371:            }
372:
373:            /* (non-Javadoc)
374:             * Method declared on PartPane.
375:             */
376:            /* package */
377:            void shellDeactivated() {
378:            }
379:
380:            /**
381:             * Set the active border.
382:             * @param active
383:             */
384:            void setActive(boolean active) {
385:                hasFocus = active;
386:
387:                if (getContainer() instanceof  PartStack) {
388:                    ((PartStack) getContainer())
389:                            .setActive(active ? StackPresentation.AS_ACTIVE_FOCUS
390:                                    : StackPresentation.AS_INACTIVE);
391:                }
392:            }
393:
394:            /**
395:             * Indicate focus in part.
396:             */
397:            public void showFocus(boolean inFocus) {
398:                setActive(inFocus);
399:            }
400:
401:            /**
402:             * Return true if this view is a fast view.
403:             */
404:            private boolean isFastView() {
405:                return page.isFastView(getViewReference());
406:            }
407:
408:            /**
409:             * Return true if the view may be moved.
410:             */
411:            boolean isMoveable() {
412:                return !page.isFixedLayout();
413:            }
414:
415:            /**
416:             * Return if there should be a view menu at all.
417:             * There is no view menu if there is no menu manager,
418:             * no pull down button or if the receiver is an
419:             * inactive fast view.
420:             */
421:            public boolean hasViewMenu() {
422:
423:                if (isvMenuMgr != null) {
424:                    return !isvMenuMgr.isEmpty();
425:                }
426:
427:                return false;
428:            }
429:
430:            public void showViewMenu(Point location) {
431:                if (!hasViewMenu()) {
432:                    return;
433:                }
434:
435:                // If this is a fast view, it may have been minimized. Do nothing in this case.
436:                if (isFastView()
437:                        && (page.getActiveFastView() != getViewReference())) {
438:                    return;
439:                }
440:
441:                Menu aMenu = isvMenuMgr.createContextMenu(getControl()
442:                        .getParent());
443:                aMenu.setLocation(location.x, location.y);
444:                aMenu.setVisible(true);
445:            }
446:
447:            public String toString() {
448:
449:                return getClass().getName()
450:                        + "@" + Integer.toHexString(hashCode()); //$NON-NLS-1$
451:            }
452:
453:            /**
454:             * @see ViewActionBars
455:             */
456:            public void updateActionBars() {
457:                if (isvMenuMgr != null) {
458:                    isvMenuMgr.update(false);
459:                }
460:                if (isvToolBarMgr != null) {
461:                    isvToolBarMgr.update(false);
462:                }
463:
464:            }
465:
466:            /**
467:             * Update the title attributes.
468:             */
469:            public void updateTitles() {
470:                firePropertyChange(IPresentablePart.PROP_TITLE);
471:            }
472:
473:            /* (non-Javadoc)
474:             * @see org.eclipse.ui.internal.PartPane#addSizeMenuItem(org.eclipse.swt.widgets.Menu)
475:             */
476:            public void addSizeMenuItem(Menu menu, int index) {
477:                if (isMoveable()) {
478:                    super .addSizeMenuItem(menu, index);
479:                }
480:            }
481:
482:            /* (non-Javadoc)
483:             * @see org.eclipse.ui.internal.PartPane#doZoom()
484:             */
485:            protected void doZoom() {
486:                if (isMoveable()) {
487:                    super .doZoom();
488:                }
489:            }
490:
491:            /* (non-Javadoc)
492:             * @see org.eclipse.ui.internal.LayoutPart#setContainer(org.eclipse.ui.internal.ILayoutContainer)
493:             */
494:            public void setContainer(ILayoutContainer container) {
495:                ILayoutContainer oldContainer = getContainer();
496:                if (hasFocus) {
497:                    if (oldContainer != null
498:                            && oldContainer instanceof  PartStack) {
499:                        ((PartStack) oldContainer)
500:                                .setActive(StackPresentation.AS_INACTIVE);
501:                    }
502:
503:                    if (container != null && container instanceof  PartStack) {
504:                        ((PartStack) container)
505:                                .setActive(StackPresentation.AS_ACTIVE_FOCUS);
506:                    }
507:                }
508:
509:                super .setContainer(container);
510:            }
511:
512:            /* (non-Javadoc)
513:             * @see org.eclipse.ui.internal.LayoutPart#reparent(org.eclipse.swt.widgets.Composite)
514:             */
515:            public void reparent(Composite newParent) {
516:                super .reparent(newParent);
517:
518:                if (isvToolBarMgr != null) {
519:                    Control bar = isvToolBarMgr.getControl2();
520:                    if (bar != null) {
521:                        bar.setParent(newParent);
522:                        bar.moveAbove(control);
523:                    }
524:                }
525:            }
526:
527:            /* (non-Javadoc)
528:             * @see org.eclipse.ui.internal.LayoutPart#moveAbove(org.eclipse.swt.widgets.Control)
529:             */
530:            public void moveAbove(Control refControl) {
531:                super .moveAbove(refControl);
532:
533:                Control toolbar = internalGetToolbar();
534:
535:                if (toolbar != null) {
536:                    toolbar.moveAbove(control);
537:                }
538:            }
539:
540:            /* (non-Javadoc)
541:             * @see org.eclipse.ui.internal.LayoutPart#setVisible(boolean)
542:             */
543:            public void setVisible(boolean makeVisible) {
544:                super .setVisible(makeVisible);
545:
546:                Control toolbar = internalGetToolbar();
547:
548:                if (toolbar != null) {
549:                    boolean visible = makeVisible && toolbarIsVisible();
550:                    toolbar.setVisible(visible);
551:                }
552:            }
553:
554:            public boolean toolbarIsVisible() {
555:                IToolBarManager2 toolbarManager = getToolBarManager();
556:
557:                if (toolbarManager == null) {
558:                    return false;
559:                }
560:
561:                Control control = toolbarManager.getControl2();
562:
563:                if (control == null || control.isDisposed()) {
564:                    return false;
565:                }
566:
567:                return toolbarManager.getItemCount() > 0;
568:            }
569:
570:            /* (non-Javadoc)
571:             * @see org.eclipse.ui.internal.PartPane#showHighlight()
572:             */
573:            public void showHighlight() {
574:                firePropertyChange(IPresentablePart.PROP_HIGHLIGHT_IF_BACK);
575:            }
576:
577:            /* (non-Javadoc)
578:             * @see org.eclipse.ui.internal.LayoutPart#getPlaceHolderId()
579:             */
580:            public String getPlaceHolderId() {
581:                return ViewFactory.getKey(getViewReference());
582:            }
583:
584:            /* (non-Javadoc)
585:             * @see org.eclipse.ui.internal.PartPane#getToolBar()
586:             */
587:            public Control getToolBar() {
588:
589:                if (!toolbarIsVisible()) {
590:                    return null;
591:                }
592:
593:                return internalGetToolbar();
594:            }
595:
596:            private Control internalGetToolbar() {
597:                if (isvToolBarMgr == null) {
598:                    return null;
599:                }
600:
601:                return isvToolBarMgr.getControl2();
602:            }
603:
604:            /* (non-Javadoc)
605:             * @see org.eclipse.ui.internal.PartPane#isCloseable()
606:             */
607:            public boolean isCloseable() {
608:                Perspective perspective = page.getActivePerspective();
609:                if (perspective == null) {
610:                    // Shouldn't happen -- can't have a ViewStack without a
611:                    // perspective
612:                    return true;
613:                }
614:                return perspective.isCloseable(getViewReference());
615:            }
616:
617:            public void showSystemMenu() {
618:                if (isFastView()) {
619:                    Perspective perspective = page.getActivePerspective();
620:                    if (perspective != null) {
621:                        perspective.getFastViewPane().showSystemMenu();
622:                    }
623:                } else {
624:                    super .showSystemMenu();
625:                }
626:            }
627:
628:            public void showPaneMenu() {
629:                if (isFastView()) {
630:                    Perspective perspective = page.getActivePerspective();
631:                    if (perspective != null) {
632:                        perspective.getFastViewPane().showPaneMenu();
633:                    }
634:                } else {
635:                    super .showPaneMenu();
636:                }
637:            }
638:
639:            public void removeContributions() {
640:                super.removeContributions();
641:
642:                if (isvMenuMgr != null) {
643:                    isvMenuMgr.removeAll();
644:                }
645:                if (isvToolBarMgr != null) {
646:                    isvToolBarMgr.removeAll();
647:                }
648:            }
649:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.