Source Code Cross Referenced for PageLayout.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:         *     Dan Rubel <dan_rubel@instantiations.com>
011:         *     - Fix for bug 11490 - define hidden view (placeholder for view) in plugin.xml
012:         *     Ted Stockwell <emorning@yahoo.com>
013:         *     - Fix for bug 63595 - IPageLayout.addFastView regression (3.0M8 to 3.0M9)
014:         *     Chris Gross <schtoo@schtoo.com> 
015:         *     - Fix for 99155 - allow standalone view placeholders
016:         *     Chris Gross chris.gross@us.ibm.com Bug 107443
017:         *******************************************************************************/package org.eclipse.ui.internal;
018:
019:        import java.util.ArrayList;
020:        import java.util.HashMap;
021:        import java.util.List;
022:        import java.util.Map;
023:
024:        import org.eclipse.osgi.util.NLS;
025:        import org.eclipse.swt.SWT;
026:        import org.eclipse.ui.IFolderLayout;
027:        import org.eclipse.ui.IPageLayout;
028:        import org.eclipse.ui.IPerspectiveDescriptor;
029:        import org.eclipse.ui.IPlaceholderFolderLayout;
030:        import org.eclipse.ui.IViewLayout;
031:        import org.eclipse.ui.IViewReference;
032:        import org.eclipse.ui.PartInitException;
033:        import org.eclipse.ui.activities.WorkbenchActivityHelper;
034:        import org.eclipse.ui.internal.presentations.PresentationFactoryUtil;
035:        import org.eclipse.ui.internal.registry.ActionSetRegistry;
036:        import org.eclipse.ui.internal.registry.IActionSetDescriptor;
037:        import org.eclipse.ui.views.IViewDescriptor;
038:        import org.eclipse.ui.views.IViewRegistry;
039:
040:        /**
041:         * This factory is used to define the initial layout of a part sash container.
042:         * <p>
043:         * Design notes: The design of <code>IPageLayout</code> is a reflection of 
044:         * three requirements:
045:         * <ol>
046:         *   <li>A mechanism is required to define the initial layout for a page. </li>
047:         *   <li>The views and editors within a page will be persisted between 
048:         *     sessions.</li>
049:         *   <li>The view and editor lifecycle for (1) and (2) should be identical.</li>
050:         * </ol>
051:         * </p>
052:         * <p>
053:         * In reflection of these requirements, the following strategy has been 
054:         * implemented for layout definition.
055:         * <ol>
056:         *   <li>A view extension is added to the workbench registry for the view. 
057:         *     This extension defines the extension id and extension class.  </li>
058:         *   <li>A view is added to a page by invoking one of the add methods
059:         *     in <code>IPageLayout</code>. The type of view is passed as an 
060:         *     extension id, rather than a handle. The page layout will map 
061:         *     the extension id to a view class, create an instance of the class, 
062:         *     and then add the view to the page.</li>
063:         * </ol>
064:         * </p>
065:         */
066:        public class PageLayout implements  IPageLayout {
067:            private ArrayList actionSets = new ArrayList(3);
068:
069:            private IPerspectiveDescriptor descriptor;
070:
071:            private LayoutPart editorFolder;
072:
073:            private boolean editorVisible = true;
074:
075:            private boolean fixed;
076:
077:            private ArrayList fastViews = new ArrayList(3);
078:
079:            private Map mapIDtoFolder = new HashMap(10);
080:
081:            private Map mapIDtoPart = new HashMap(10);
082:
083:            private Map mapIDtoViewLayoutRec = new HashMap(10);
084:
085:            private Map mapFolderToFolderLayout = new HashMap(10);
086:
087:            private ArrayList newWizardShortcuts = new ArrayList(3);
088:
089:            private ArrayList perspectiveShortcuts = new ArrayList(3);
090:
091:            private ViewSashContainer rootLayoutContainer;
092:
093:            private ArrayList showInPartIds = new ArrayList(3);
094:
095:            private ArrayList showViewShortcuts = new ArrayList(3);
096:
097:            private ViewFactory viewFactory;
098:
099:            private List minimizedStacks = new ArrayList();
100:
101:            /**
102:             * Constructs a new PageLayout for other purposes.
103:             */
104:            public PageLayout() {
105:                //no-op
106:            }
107:
108:            /**
109:             * Constructs a new PageLayout for the normal case of creating a new
110:             * perspective.
111:             */
112:            public PageLayout(ViewSashContainer container,
113:                    ViewFactory viewFactory, LayoutPart editorFolder,
114:                    IPerspectiveDescriptor descriptor) {
115:                super ();
116:                this .viewFactory = viewFactory;
117:                this .rootLayoutContainer = container;
118:                this .editorFolder = editorFolder;
119:                this .descriptor = descriptor;
120:                prefill();
121:            }
122:
123:            /**
124:             * Adds the editor to a layout.
125:             */
126:            private void addEditorArea() {
127:                try {
128:                    // Create the part.
129:                    LayoutPart newPart = createView(ID_EDITOR_AREA);
130:                    if (newPart == null) {
131:                        // this should never happen as long as newID is the editor ID.
132:                        return;
133:                    }
134:
135:                    setRefPart(ID_EDITOR_AREA, newPart);
136:
137:                    // Add it to the layout.
138:                    rootLayoutContainer.add(newPart);
139:                } catch (PartInitException e) {
140:                    WorkbenchPlugin.log(getClass(), "addEditorArea()", e); //$NON-NLS-1$
141:                }
142:            }
143:
144:            /**
145:             * Adds an action set to the page.
146:             * 
147:             * @param actionSetID Identifies the action set extension to use. It must
148:             *            exist within the workbench registry.
149:             */
150:            public void addActionSet(String actionSetID) {
151:                if (!actionSets.contains(actionSetID)) {
152:                    actionSets.add(actionSetID);
153:                }
154:            }
155:
156:            /* (non-Javadoc)
157:             * @see org.eclipse.ui.IPageLayout#addFastView(java.lang.String)
158:             */
159:            public void addFastView(String id) {
160:                addFastView(id, INVALID_RATIO);
161:            }
162:
163:            /* (non-Javadoc)
164:             * @see org.eclipse.ui.IPageLayout#addFastView(java.lang.String, float)
165:             */
166:            public void addFastView(String id, float ratio) {
167:                if (checkPartInLayout(id)) {
168:                    return;
169:                }
170:                if (id != null) {
171:                    try {
172:                        IViewDescriptor viewDescriptor = viewFactory
173:                                .getViewRegistry().find(
174:                                        ViewFactory.extractPrimaryId(id));
175:                        if (!WorkbenchActivityHelper.filterItem(viewDescriptor)) {
176:                            IViewReference ref = viewFactory.createView(
177:                                    ViewFactory.extractPrimaryId(id),
178:                                    ViewFactory.extractSecondaryId(id));
179:                            fastViews.add(ref);
180:
181:                            // force creation of the view layout rec
182:                            ViewLayoutRec rec = getViewLayoutRec(id, true);
183:
184:                            // remember the ratio, if valid
185:                            if (ratio >= IPageLayout.RATIO_MIN
186:                                    && ratio <= IPageLayout.RATIO_MAX) {
187:                                rec.fastViewWidthRatio = ratio;
188:                            }
189:                        }
190:                    } catch (PartInitException e) {
191:                        WorkbenchPlugin.log(getClass(), "addFastView", e); //$NON-NLS-1$
192:                    }
193:                }
194:            }
195:
196:            /**
197:             * Check to see if the partId represents a fast view's id.
198:             * 
199:             * @param partId
200:             *            The part's id.
201:             * @return true if the partId is a fast view id.
202:             */
203:            private boolean isFastViewId(String partId) {
204:                for (int i = 0; i < fastViews.size(); i++) {
205:                    IViewReference ref = (IViewReference) fastViews.get(i);
206:                    String secondaryId = ref.getSecondaryId();
207:                    String refId = (secondaryId == null ? ref.getId() : ref
208:                            .getId()
209:                            + ":" + secondaryId); //$NON-NLS-1$
210:                    if (refId.equals(partId)) {
211:                        return true;
212:                    }
213:                }
214:                return false;
215:            }
216:
217:            /**
218:             * Returns the view layout record for the given view id, or null if not
219:             * found. If create is true, the record is created if it doesn't already
220:             * exist.
221:             * 
222:             * @since 3.0
223:             */
224:            ViewLayoutRec getViewLayoutRec(String id, boolean create) {
225:                ViewLayoutRec rec = (ViewLayoutRec) mapIDtoViewLayoutRec
226:                        .get(id);
227:                if (rec == null && create) {
228:                    rec = new ViewLayoutRec();
229:                    // set up the view layout appropriately if the page layout is fixed
230:                    if (isFixed()) {
231:                        rec.isCloseable = false;
232:                        rec.isMoveable = false;
233:                    }
234:                    mapIDtoViewLayoutRec.put(id, rec);
235:                }
236:                return rec;
237:            }
238:
239:            /**
240:             * Adds a creation wizard to the File New menu.
241:             * The id must name a new wizard extension contributed to the 
242:             * workbench's extension point (named <code>"org.eclipse.ui.newWizards"</code>).
243:             *
244:             * @param id the wizard id
245:             */
246:            public void addNewWizardShortcut(String id) {
247:                if (!newWizardShortcuts.contains(id)) {
248:                    newWizardShortcuts.add(id);
249:                }
250:            }
251:
252:            /**
253:             * Add the layout part to the page's layout
254:             */
255:            private void addPart(LayoutPart newPart, String partId,
256:                    int relationship, float ratio, String refId) {
257:
258:                setRefPart(partId, newPart);
259:
260:                // If the referenced part is inside a folder,
261:                // then use the folder as the reference part.
262:                LayoutPart refPart = getFolderPart(refId);
263:                if (refPart == null) {
264:                    refPart = getRefPart(refId);
265:                }
266:
267:                // Add it to the layout.
268:                if (refPart != null) {
269:                    ratio = normalizeRatio(ratio);
270:                    rootLayoutContainer.add(newPart,
271:                            getPartSashConst(relationship), ratio, refPart);
272:                } else {
273:                    WorkbenchPlugin
274:                            .log(NLS
275:                                    .bind(
276:                                            WorkbenchMessages.PageLayout_missingRefPart,
277:                                            refId));
278:                    rootLayoutContainer.add(newPart);
279:                }
280:            }
281:
282:            /**
283:             * Adds a perspective shortcut to the Perspective menu.
284:             * The id must name a perspective extension contributed to the 
285:             * workbench's extension point (named <code>"org.eclipse.ui.perspectives"</code>).
286:             *
287:             * @param id the perspective id
288:             */
289:            public void addPerspectiveShortcut(String id) {
290:                if (!perspectiveShortcuts.contains(id)) {
291:                    perspectiveShortcuts.add(id);
292:                }
293:            }
294:
295:            /* (non-Javadoc)
296:             * @see org.eclipse.ui.IPageLayout#addPlaceholder(java.lang.String, int, float, java.lang.String)
297:             */
298:            public void addPlaceholder(String viewId, int relationship,
299:                    float ratio, String refId) {
300:                if (!checkValidPlaceholderId(viewId)) {
301:                    return;
302:                }
303:
304:                // Create the placeholder.
305:                PartPlaceholder newPart = new PartPlaceholder(viewId);
306:                addPart(newPart, viewId, relationship, ratio, refId);
307:                // force creation of the view layout rec
308:                getViewLayoutRec(viewId, true);
309:            }
310:
311:            /**
312:             * Checks whether the given id is a valid placeholder id.
313:             * A placeholder id may be simple or compound, and can optionally contain a wildcard.
314:             * 
315:             * @param id the placeholder id
316:             * @return <code>true</code> if the given id is a valid placeholder id, <code>false</code> otherwise
317:             */
318:            boolean checkValidPlaceholderId(String id) {
319:                // Check that view is not already in layout.
320:                // This check is done even if the id has a wildcard, since it's incorrect to create
321:                // multiple placeholders with the same id, wildcard or not.
322:                if (checkPartInLayout(id)) {
323:                    return false;
324:                }
325:
326:                // check that primary view id is valid, but only if it has no wildcard
327:                String primaryId = ViewFactory.extractPrimaryId(id);
328:                if (!ViewFactory.hasWildcard(primaryId)) {
329:                    IViewRegistry reg = WorkbenchPlugin.getDefault()
330:                            .getViewRegistry();
331:                    IViewDescriptor desc = reg.find(primaryId);
332:                    if (desc == null) {
333:                        // cannot safely open the dialog so log the problem
334:                        WorkbenchPlugin
335:                                .log("Unable to find view with id: " + primaryId + ", when creating perspective " + getDescriptor().getId()); //$NON-NLS-1$ //$NON-NLS-2$
336:                        return false;
337:                    }
338:                }
339:
340:                return true;
341:            }
342:
343:            /* (non-Javadoc)
344:             * @see org.eclipse.ui.IPageLayout#addShowInPart(java.lang.String)
345:             */
346:            public void addShowInPart(String id) {
347:                if (!showInPartIds.contains(id)) {
348:                    showInPartIds.add(id);
349:                }
350:            }
351:
352:            /**
353:             * Adds a view to the Show View menu. The id must name a view extension
354:             * contributed to the workbench's extension point (named <code>"org.eclipse.ui.views"</code>).
355:             * 
356:             * @param id the view id
357:             */
358:            public void addShowViewShortcut(String id) {
359:                if (!showViewShortcuts.contains(id)) {
360:                    showViewShortcuts.add(id);
361:                }
362:            }
363:
364:            /* (non-Javadoc)
365:             * @see org.eclipse.ui.IPageLayout#addView(java.lang.String, int, float, java.lang.String)
366:             */
367:            public void addView(String viewId, int relationship, float ratio,
368:                    String refId) {
369:                addView(viewId, relationship, ratio, refId, false, false, true);
370:            }
371:
372:            /**
373:             * Convenience method to allow setting the initial minimized
374:             * state if a new stack is created. Used by the 'perspectiveExtension'
375:             * reader.
376:             * 
377:             *  @since 3.3
378:             */
379:            public void addView(String viewId, int relationship, float ratio,
380:                    String refId, boolean minimized) {
381:                addView(viewId, relationship, ratio, refId, minimized, false,
382:                        true);
383:            }
384:
385:            /* (non-Javadoc)
386:             * @see org.eclipse.ui.IPageLayout#addView(java.lang.String, int, float, java.lang.String)
387:             */
388:            private void addView(String viewId, int relationship, float ratio,
389:                    String refId, boolean minimized, boolean standalone,
390:                    boolean showTitle) {
391:                if (checkPartInLayout(viewId)) {
392:                    return;
393:                }
394:
395:                try {
396:                    // Create the part.
397:                    LayoutPart newPart = createView(viewId);
398:                    if (newPart == null) {
399:                        addPlaceholder(viewId, relationship, ratio, refId);
400:                        LayoutHelper.addViewActivator(this , viewId);
401:                    } else {
402:                        int appearance = PresentationFactoryUtil.ROLE_VIEW;
403:                        if (standalone) {
404:                            if (showTitle) {
405:                                appearance = PresentationFactoryUtil.ROLE_STANDALONE;
406:                            } else {
407:                                appearance = PresentationFactoryUtil.ROLE_STANDALONE_NOTITLE;
408:                            }
409:                        }
410:
411:                        ViewStack newFolder = new ViewStack(
412:                                rootLayoutContainer.page, true, appearance,
413:                                null);
414:                        newFolder.add(newPart);
415:                        setFolderPart(viewId, newFolder);
416:                        addPart(newFolder, viewId, relationship, ratio, refId);
417:                        // force creation of the view layout rec
418:                        getViewLayoutRec(viewId, true);
419:
420:                        // Capture any minimized stacks
421:                        if (minimized) {
422:                            // Remember the minimized stacks so we can
423:                            // move them to the trim when the Perspective
424:                            // activates...
425:                            minimizedStacks.add(newFolder);
426:                        }
427:                    }
428:                } catch (PartInitException e) {
429:                    WorkbenchPlugin.log(getClass(), "addView", e); //$NON-NLS-1$
430:                }
431:            }
432:
433:            public List getMinimizedStacks() {
434:                return minimizedStacks;
435:            }
436:
437:            /**
438:             * Verify that the part is already present in the layout
439:             * and cannot be added again. Log a warning message.
440:             */
441:            /*package*/
442:            boolean checkPartInLayout(String partId) {
443:                if (getRefPart(partId) != null || isFastViewId(partId)) {
444:                    WorkbenchPlugin.log(NLS.bind(
445:                            WorkbenchMessages.PageLayout_duplicateRefPart,
446:                            partId));
447:                    return true;
448:                }
449:
450:                return false;
451:            }
452:
453:            /* (non-Javadoc)
454:             * @see org.eclipse.ui.IPageLayout#createFolder(java.lang.String, int, float, java.lang.String)
455:             */
456:            public IFolderLayout createFolder(String folderId,
457:                    int relationship, float ratio, String refId) {
458:                if (checkPartInLayout(folderId)) {
459:                    ViewStack folder = (ViewStack) getRefPart(folderId);
460:
461:                    return (IFolderLayout) mapFolderToFolderLayout.get(folder);
462:                }
463:
464:                // Create the folder.
465:                ViewStack folder = new ViewStack(rootLayoutContainer.page);
466:                folder.setID(folderId);
467:                addPart(folder, folderId, relationship, ratio, refId);
468:
469:                // Create a wrapper.
470:                FolderLayout layout = new FolderLayout(this , folder,
471:                        viewFactory);
472:
473:                mapFolderToFolderLayout.put(folder, layout);
474:
475:                return layout;
476:            }
477:
478:            /* (non-Javadoc)
479:             * @see org.eclipse.ui.IPageLayout#createPlaceholderFolder(java.lang.String, int, float, java.lang.String)
480:             */
481:            public IPlaceholderFolderLayout createPlaceholderFolder(
482:                    String folderId, int relationship, float ratio, String refId) {
483:                if (checkPartInLayout(folderId)) {
484:                    ContainerPlaceholder folder = (ContainerPlaceholder) getRefPart(folderId);
485:
486:                    return (IPlaceholderFolderLayout) mapFolderToFolderLayout
487:                            .get(folder);
488:                }
489:
490:                // Create the folder.
491:                ContainerPlaceholder folder = new ContainerPlaceholder(null);
492:                folder.setContainer(rootLayoutContainer);
493:                folder
494:                        .setRealContainer(new ViewStack(
495:                                rootLayoutContainer.page));
496:                folder.setID(folderId);
497:                addPart(folder, folderId, relationship, ratio, refId);
498:
499:                // Create a wrapper.
500:                IPlaceholderFolderLayout layout = new PlaceholderFolderLayout(
501:                        this , folder);
502:
503:                mapFolderToFolderLayout.put(folder, layout);
504:
505:                return layout;
506:            }
507:
508:            /**
509:             * Create a new <code>LayoutPart</code>.
510:             * 
511:             * @param partID the id of the part to create.
512:             * @return the <code>LayoutPart</code>, or <code>null</code> if it should not be
513:             * created because of activity filtering.
514:             * @throws PartInitException thrown if there is a problem creating the part.
515:             */
516:            private LayoutPart createView(String partID)
517:                    throws PartInitException {
518:                if (partID.equals(ID_EDITOR_AREA)) {
519:                    return editorFolder;
520:                }
521:                IViewDescriptor viewDescriptor = viewFactory.getViewRegistry()
522:                        .find(ViewFactory.extractPrimaryId(partID));
523:                if (WorkbenchActivityHelper.filterItem(viewDescriptor)) {
524:                    return null;
525:                }
526:                return LayoutHelper.createView(getViewFactory(), partID);
527:            }
528:
529:            /**
530:             * @return the action set list for the page. This is <code>List</code> of 
531:             * <code>String</code>s.
532:             */
533:            public ArrayList getActionSets() {
534:                return actionSets;
535:            }
536:
537:            /* (non-Javadoc)
538:             * @see org.eclipse.ui.IPageLayout#getDescriptor()
539:             */
540:            public IPerspectiveDescriptor getDescriptor() {
541:                return descriptor;
542:            }
543:
544:            /**
545:             * @return an identifier for the editor area. The editor area is
546:             * automatically added to each layout before any other part. It should be
547:             * used as a reference part for other views.
548:             */
549:            public String getEditorArea() {
550:                return ID_EDITOR_AREA;
551:            }
552:
553:            /* (non-Javadoc)
554:             * @see org.eclipse.ui.IPageLayout#getEditorReuseThreshold()
555:             */
556:            public int getEditorReuseThreshold() {
557:                return -1;
558:            }
559:
560:            /**
561:             * @return <code>ArrayList</code>
562:             */
563:            public ArrayList getFastViews() {
564:                return fastViews;
565:            }
566:
567:            /**
568:             * @return the folder part containing the given view ID or <code>null</code>
569:             * if none (i.e. part of the page layout instead of a folder layout).
570:             */
571:            private ViewStack getFolderPart(String viewId) {
572:                return (ViewStack) mapIDtoFolder.get(viewId);
573:            }
574:
575:            /**
576:             * @return the new wizard shortcuts associated with the page. This is a <code>List</code> of 
577:             * <code>String</code>s.
578:             */
579:            public ArrayList getNewWizardShortcuts() {
580:                return newWizardShortcuts;
581:            }
582:
583:            /**
584:             * @return the part sash container const for a layout value.
585:             */
586:            private int getPartSashConst(int nRelationship) {
587:                return nRelationship;
588:            }
589:
590:            /**
591:             * @return the perspective shortcuts associated with the page. This is a <code>List</code> of 
592:             * <code>String</code>s.
593:             */
594:            public ArrayList getPerspectiveShortcuts() {
595:                return perspectiveShortcuts;
596:            }
597:
598:            /**
599:             * @return the part for a given ID.
600:             */
601:            /*package*/
602:            LayoutPart getRefPart(String partID) {
603:                return (LayoutPart) mapIDtoPart.get(partID);
604:            }
605:
606:            /**
607:             * @return the top level layout container.
608:             */
609:            public ViewSashContainer getRootLayoutContainer() {
610:                return rootLayoutContainer;
611:            }
612:
613:            /**
614:             * @return the ids of the parts to list in the Show In... prompter. This is
615:             * a <code>List</code> of <code>String</code>s.
616:             */
617:            public ArrayList getShowInPartIds() {
618:                return showInPartIds;
619:            }
620:
621:            /**
622:             * @return the show view shortcuts associated with the page. This is a <code>List</code> of 
623:             * <code>String</code>s.
624:             */
625:            public ArrayList getShowViewShortcuts() {
626:                return showViewShortcuts;
627:            }
628:
629:            /**
630:             * @return the <code>ViewFactory</code> for this <code>PageLayout</code>.
631:             * @since 3.0
632:             */
633:            /* package */
634:            ViewFactory getViewFactory() {
635:                return viewFactory;
636:            }
637:
638:            /* (non-Javadoc)
639:             * @see org.eclipse.ui.IPageLayout#isEditorAreaVisible()
640:             */
641:            public boolean isEditorAreaVisible() {
642:                return editorVisible;
643:            }
644:
645:            /**
646:             * Trim the ratio so that direct manipulation of parts is easy.
647:             * 
648:             * @param in the initial ratio.
649:             * @return the normalized ratio.
650:             */
651:            private float normalizeRatio(float in) {
652:                if (in < RATIO_MIN) {
653:                    in = RATIO_MIN;
654:                }
655:                if (in > RATIO_MAX) {
656:                    in = RATIO_MAX;
657:                }
658:                return in;
659:            }
660:
661:            /**
662:             * Prefill the layout with required parts.
663:             */
664:            private void prefill() {
665:                addEditorArea();
666:
667:                // Add default action sets.
668:                ActionSetRegistry reg = WorkbenchPlugin.getDefault()
669:                        .getActionSetRegistry();
670:                IActionSetDescriptor[] array = reg.getActionSets();
671:                int count = array.length;
672:                for (int nX = 0; nX < count; nX++) {
673:                    IActionSetDescriptor desc = array[nX];
674:                    if (desc.isInitiallyVisible()) {
675:                        addActionSet(desc.getId());
676:                    }
677:                }
678:            }
679:
680:            /* (non-Javadoc)
681:             * @see org.eclipse.ui.IPageLayout#setEditorAreaVisible(boolean)
682:             */
683:            public void setEditorAreaVisible(boolean showEditorArea) {
684:                editorVisible = showEditorArea;
685:            }
686:
687:            /* (non-Javadoc)
688:             * @see org.eclipse.ui.IPageLayout#setEditorReuseThreshold(int)
689:             */
690:            public void setEditorReuseThreshold(int openEditors) {
691:                //no-op
692:            }
693:
694:            /* (non-Javadoc)
695:             * @see org.eclipse.ui.IPageLayout#setFixed(boolean)
696:             */
697:            public void setFixed(boolean fixed) {
698:                this .fixed = fixed;
699:            }
700:
701:            /* (non-Javadoc)
702:             * @see org.eclipse.ui.IPageLayout#getFixed()
703:             */
704:            public boolean isFixed() {
705:                return fixed;
706:            }
707:
708:            /**
709:             * Map the folder part containing the given view ID.
710:             * 
711:             * @param viewId the part ID.
712:             * @param container the <code>ContainerPlaceholder</code>.
713:             */
714:            /*package*/
715:            void setFolderPart(String viewId, ContainerPlaceholder container) {
716:                LayoutPart tabFolder = container.getRealContainer();
717:                mapIDtoFolder.put(viewId, tabFolder);
718:            }
719:
720:            /**
721:             * Map the folder part containing the given view ID.
722:             * 
723:             * @param viewId the part ID.
724:             * @param folder the <code>ViewStack</code>.
725:             */
726:            /*package*/
727:            void setFolderPart(String viewId, ViewStack folder) {
728:                mapIDtoFolder.put(viewId, folder);
729:            }
730:
731:            /**
732:             * Map an ID to a part.
733:             * 
734:             * @param partId the part ID.
735:             * @param part the <code>LayoutPart</code>.
736:             */
737:            /*package*/
738:            void setRefPart(String partID, LayoutPart part) {
739:                mapIDtoPart.put(partID, part);
740:            }
741:
742:            // stackPart(Layoutpart, String, String) added by dan_rubel@instantiations.com
743:            /**
744:             * Stack a part on top of another.
745:             * 
746:             * @param newPart the new part.
747:             * @param viewId the view ID.
748:             * @param refId the reference ID.
749:             */
750:            private void stackPart(LayoutPart newPart, String viewId,
751:                    String refId) {
752:                setRefPart(viewId, newPart);
753:                // force creation of the view layout rec
754:                getViewLayoutRec(viewId, true);
755:
756:                // If ref part is in a folder than just add the
757:                // new view to that folder.
758:                ViewStack folder = getFolderPart(refId);
759:                if (folder != null) {
760:                    folder.add(newPart);
761:                    setFolderPart(viewId, folder);
762:                    return;
763:                }
764:
765:                // If the ref part is in the page layout then create
766:                // a new folder and add the new view.
767:                LayoutPart refPart = getRefPart(refId);
768:                if (refPart != null
769:                        && (refPart instanceof  PartPane || refPart instanceof  PartPlaceholder)) {
770:                    ViewStack newFolder = new ViewStack(
771:                            rootLayoutContainer.page);
772:                    rootLayoutContainer.replace(refPart, newFolder);
773:                    newFolder.add(refPart);
774:                    newFolder.add(newPart);
775:                    setFolderPart(refId, newFolder);
776:                    setFolderPart(viewId, newFolder);
777:                    return;
778:                }
779:
780:                // If ref part is not found then just do add.
781:                WorkbenchPlugin.log(NLS.bind(
782:                        WorkbenchMessages.PageLayout_missingRefPart, refId));
783:                rootLayoutContainer.add(newPart);
784:            }
785:
786:            // stackPlaceholder(String, String) added by dan_rubel@instantiations.com
787:            /**
788:             * Stack a placeholder on top of another.
789:             * 
790:             * @param viewId the view ID.
791:             * @param refId the reference ID.
792:             */
793:            public void stackPlaceholder(String viewId, String refId) {
794:                if (checkPartInLayout(viewId)) {
795:                    return;
796:                }
797:
798:                // Create the placeholder.
799:                PartPlaceholder newPart = new PartPlaceholder(viewId);
800:
801:                LayoutPart refPart = getRefPart(refId);
802:                if (refPart != null) {
803:                    newPart.setContainer(refPart.getContainer());
804:                }
805:
806:                stackPart(newPart, viewId, refId);
807:            }
808:
809:            // stackView(String, String) modified by dan_rubel@instantiations.com
810:            /**
811:             * Stack one view on top of another.
812:             * 
813:             * @param viewId the view ID.
814:             * @param refId the reference ID.
815:             */
816:            public void stackView(String viewId, String refId) {
817:                if (checkPartInLayout(viewId)) {
818:                    return;
819:                }
820:
821:                // Create the new part.
822:                try {
823:                    LayoutPart newPart = createView(viewId);
824:                    if (newPart == null) {
825:                        stackPlaceholder(viewId, refId);
826:                        LayoutHelper.addViewActivator(this , viewId);
827:                    } else {
828:                        stackPart(newPart, viewId, refId);
829:                    }
830:                } catch (PartInitException e) {
831:                    WorkbenchPlugin.log(getClass(), "stackView", e); //$NON-NLS-1$
832:                }
833:            }
834:
835:            /**
836:             * Converts SWT position constants into layout position constants.
837:             * 
838:             * @param swtConstant one of SWT.TOP, SWT.BOTTOM, SWT.LEFT, or SWT.RIGHT
839:             * @return one of IPageLayout.TOP, IPageLayout.BOTTOM, IPageLayout.LEFT, IPageLayout.RIGHT, or -1 indicating an
840:             * invalid input
841:             * 
842:             * @since 3.0
843:             */
844:            public static int swtConstantToLayoutPosition(int swtConstant) {
845:                switch (swtConstant) {
846:                case SWT.TOP:
847:                    return IPageLayout.TOP;
848:                case SWT.BOTTOM:
849:                    return IPageLayout.BOTTOM;
850:                case SWT.RIGHT:
851:                    return IPageLayout.RIGHT;
852:                case SWT.LEFT:
853:                    return IPageLayout.LEFT;
854:                }
855:
856:                return -1;
857:            }
858:
859:            /* (non-Javadoc)
860:             * @see org.eclipse.ui.IPageLayout#addStandaloneView(java.lang.String, boolean, int, float, java.lang.String)
861:             * @since 3.0
862:             */
863:            public void addStandaloneView(String viewId, boolean showTitle,
864:                    int relationship, float ratio, String refId) {
865:                addView(viewId, relationship, ratio, refId, false, true,
866:                        showTitle);
867:                ViewLayoutRec rec = getViewLayoutRec(viewId, true);
868:                rec.isStandalone = true;
869:                rec.showTitle = showTitle;
870:            }
871:
872:            /* (non-Javadoc)
873:             * @see org.eclipse.ui.IPageLayout#addStandaloneViewPlaceholder(java.lang.String, int, float, java.lang.String, boolean)
874:             */
875:            public void addStandaloneViewPlaceholder(String viewId,
876:                    int relationship, float ratio, String refId,
877:                    boolean showTitle) {
878:
879:                String stackId = viewId + ".standalonefolder"; //$NON-NLS-1$
880:
881:                // Check to see if the view is already in the layout
882:                if (!checkValidPlaceholderId(viewId)) {
883:                    return;
884:                }
885:
886:                // Create the folder.
887:                ContainerPlaceholder folder = new ContainerPlaceholder(null);
888:                folder.setContainer(rootLayoutContainer);
889:                int appearance = PresentationFactoryUtil.ROLE_STANDALONE;
890:                if (!showTitle) {
891:                    appearance = PresentationFactoryUtil.ROLE_STANDALONE_NOTITLE;
892:                }
893:                folder.setRealContainer(new ViewStack(rootLayoutContainer.page,
894:                        true, appearance, null));
895:                folder.setID(stackId);
896:                addPart(folder, stackId, relationship, ratio, refId);
897:
898:                // Create a wrapper.
899:                PlaceholderFolderLayout placeHolder = new PlaceholderFolderLayout(
900:                        this , folder);
901:
902:                // Add the standalone view immediately
903:                placeHolder.addPlaceholder(viewId);
904:
905:                ViewLayoutRec rec = getViewLayoutRec(viewId, true);
906:                rec.isStandalone = true;
907:                rec.showTitle = showTitle;
908:            }
909:
910:            /*
911:             * (non-Javadoc)
912:             * 
913:             * @see org.eclipse.ui.IPageLayout#getViewLayout(java.lang.String)
914:             * @since 3.0
915:             */
916:            public IViewLayout getViewLayout(String viewId) {
917:                ViewLayoutRec rec = getViewLayoutRec(viewId, true);
918:                if (rec == null) {
919:                    return null;
920:                }
921:                return new ViewLayout(this , rec);
922:            }
923:
924:            /**
925:             * @since 3.0
926:             */
927:            public Map getIDtoViewLayoutRecMap() {
928:                return mapIDtoViewLayoutRec;
929:            }
930:
931:            /**
932:             * Removes any existing placeholder with the given id.
933:             * 
934:             * @param id the id for the placeholder
935:             * @since 3.1
936:             */
937:            public void removePlaceholder(String id) {
938:                LayoutPart part = getRefPart(id);
939:                if (part instanceof  PartPlaceholder) {
940:                    ViewStack stack = getFolderPart(id);
941:                    if (stack != null) {
942:                        stack.remove(part);
943:                    } else {
944:                        rootLayoutContainer.remove(part);
945:                    }
946:                    mapIDtoPart.remove(id);
947:                    mapIDtoFolder.remove(id);
948:                    mapIDtoViewLayoutRec.remove(id);
949:                }
950:            }
951:
952:            /* (non-Javadoc)
953:             * @see org.eclipse.ui.IPageLayout#getFolderForView(java.lang.String)
954:             */
955:            public IPlaceholderFolderLayout getFolderForView(String viewId) {
956:                if (!mapIDtoFolder.containsKey(viewId))
957:                    return null;
958:
959:                ViewStack folder = (ViewStack) mapIDtoFolder.get(viewId);
960:                IPlaceholderFolderLayout layout = null;
961:                if (!mapFolderToFolderLayout.containsKey(folder)) {
962:                    layout = new FolderLayout(this , folder, viewFactory);
963:                    mapFolderToFolderLayout.put(folder, layout);
964:                } else {
965:                    layout = (IPlaceholderFolderLayout) mapFolderToFolderLayout
966:                            .get(folder);
967:                }
968:                return layout;
969:            }
970:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.