KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > browsing > JavaBrowsingPerspectiveFactory


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.browsing;
12
13 import org.eclipse.core.runtime.IAdaptable;
14 import org.eclipse.debug.ui.IDebugUIConstants;
15 import org.eclipse.jdt.core.IJavaElement;
16 import org.eclipse.jdt.ui.JavaUI;
17 import org.eclipse.jdt.ui.PreferenceConstants;
18
19 import org.eclipse.search.ui.NewSearchUI;
20 import org.eclipse.ui.IPageLayout;
21 import org.eclipse.ui.IPerspectiveFactory;
22 import org.eclipse.ui.IPlaceholderFolderLayout;
23 import org.eclipse.ui.console.IConsoleConstants;
24 import org.eclipse.ui.progress.IProgressConstants;
25
26
27 public class JavaBrowsingPerspectiveFactory implements IPerspectiveFactory {
28
29     /*
30      * XXX: This is a workaround for: http://dev.eclipse.org/bugs/show_bug.cgi?id=13070
31      */

32     static IJavaElement fgJavaElementFromAction;
33
34     /**
35      * Constructs a new Default layout engine.
36      */

37     public JavaBrowsingPerspectiveFactory() {
38         super();
39     }
40
41     public void createInitialLayout(IPageLayout layout) {
42         if (stackBrowsingViewsVertically())
43             createVerticalLayout(layout);
44         else
45             createHorizontalLayout(layout);
46
47         // action sets
48
layout.addActionSet(IDebugUIConstants.LAUNCH_ACTION_SET);
49         layout.addActionSet(JavaUI.ID_ACTION_SET);
50         layout.addActionSet(JavaUI.ID_ELEMENT_CREATION_ACTION_SET);
51         layout.addActionSet(IPageLayout.ID_NAVIGATE_ACTION_SET);
52
53         // views - java
54
layout.addShowViewShortcut(JavaUI.ID_TYPE_HIERARCHY);
55         layout.addShowViewShortcut(JavaUI.ID_PACKAGES);
56         layout.addShowViewShortcut(JavaUI.ID_PROJECTS_VIEW);
57         layout.addShowViewShortcut(JavaUI.ID_PACKAGES_VIEW);
58         layout.addShowViewShortcut(JavaUI.ID_TYPES_VIEW);
59         layout.addShowViewShortcut(JavaUI.ID_MEMBERS_VIEW);
60         layout.addShowViewShortcut(JavaUI.ID_SOURCE_VIEW);
61         layout.addShowViewShortcut(JavaUI.ID_JAVADOC_VIEW);
62
63         // views - search
64
layout.addShowViewShortcut(NewSearchUI.SEARCH_VIEW_ID);
65
66         // views - debugging
67
layout.addShowViewShortcut(IConsoleConstants.ID_CONSOLE_VIEW);
68
69         // views - standard workbench
70
layout.addShowViewShortcut(IPageLayout.ID_OUTLINE);
71         layout.addShowViewShortcut(IPageLayout.ID_PROBLEM_VIEW);
72         layout.addShowViewShortcut(IPageLayout.ID_RES_NAV);
73         layout.addShowViewShortcut(IPageLayout.ID_TASK_LIST);
74         layout.addShowViewShortcut(IProgressConstants.PROGRESS_VIEW_ID);
75
76         // new actions - Java project creation wizard
77
layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.JavaProjectWizard"); //$NON-NLS-1$
78
layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewPackageCreationWizard"); //$NON-NLS-1$
79
layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewClassCreationWizard"); //$NON-NLS-1$
80
layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewInterfaceCreationWizard"); //$NON-NLS-1$
81
layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewEnumCreationWizard"); //$NON-NLS-1$
82
layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewAnnotationCreationWizard"); //$NON-NLS-1$
83
layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewSourceFolderCreationWizard"); //$NON-NLS-1$
84
layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewSnippetFileCreationWizard"); //$NON-NLS-1$
85
layout.addNewWizardShortcut("org.eclipse.ui.wizards.new.folder");//$NON-NLS-1$
86
layout.addNewWizardShortcut("org.eclipse.ui.wizards.new.file");//$NON-NLS-1$
87
layout.addNewWizardShortcut("org.eclipse.ui.editors.wizards.UntitledTextFileWizard");//$NON-NLS-1$
88
}
89
90     private void createVerticalLayout(IPageLayout layout) {
91         String JavaDoc relativePartId= IPageLayout.ID_EDITOR_AREA;
92         int relativePos= IPageLayout.LEFT;
93
94         IPlaceholderFolderLayout placeHolderLeft= layout.createPlaceholderFolder("left", IPageLayout.LEFT, (float)0.25, IPageLayout.ID_EDITOR_AREA); //$NON-NLS-1$
95
placeHolderLeft.addPlaceholder(JavaUI.ID_TYPE_HIERARCHY);
96         placeHolderLeft.addPlaceholder(IPageLayout.ID_OUTLINE);
97         placeHolderLeft.addPlaceholder(JavaUI.ID_PACKAGES);
98         placeHolderLeft.addPlaceholder(IPageLayout.ID_RES_NAV);
99
100         if (shouldShowProjectsView()) {
101             layout.addView(JavaUI.ID_PROJECTS_VIEW, IPageLayout.LEFT, (float)0.25, IPageLayout.ID_EDITOR_AREA);
102             relativePartId= JavaUI.ID_PROJECTS_VIEW;
103             relativePos= IPageLayout.BOTTOM;
104         }
105         if (shouldShowPackagesView()) {
106             layout.addView(JavaUI.ID_PACKAGES_VIEW, relativePos, (float)0.25, relativePartId);
107             relativePartId= JavaUI.ID_PACKAGES_VIEW;
108             relativePos= IPageLayout.BOTTOM;
109         }
110         layout.addView(JavaUI.ID_TYPES_VIEW, relativePos, (float)0.33, relativePartId);
111         layout.addView(JavaUI.ID_MEMBERS_VIEW, IPageLayout.BOTTOM, (float)0.50, JavaUI.ID_TYPES_VIEW);
112
113         IPlaceholderFolderLayout placeHolderBottom= layout.createPlaceholderFolder("bottom", IPageLayout.BOTTOM, (float)0.75, IPageLayout.ID_EDITOR_AREA); //$NON-NLS-1$
114
placeHolderBottom.addPlaceholder(IPageLayout.ID_PROBLEM_VIEW);
115         placeHolderBottom.addPlaceholder(NewSearchUI.SEARCH_VIEW_ID);
116         placeHolderBottom.addPlaceholder(IConsoleConstants.ID_CONSOLE_VIEW);
117         placeHolderBottom.addPlaceholder(IPageLayout.ID_BOOKMARKS);
118         placeHolderBottom.addPlaceholder(JavaUI.ID_SOURCE_VIEW);
119         placeHolderBottom.addPlaceholder(JavaUI.ID_JAVADOC_VIEW);
120         placeHolderBottom.addPlaceholder(IProgressConstants.PROGRESS_VIEW_ID);
121     }
122
123     private void createHorizontalLayout(IPageLayout layout) {
124         String JavaDoc relativePartId= IPageLayout.ID_EDITOR_AREA;
125         int relativePos= IPageLayout.TOP;
126
127         if (shouldShowProjectsView()) {
128             layout.addView(JavaUI.ID_PROJECTS_VIEW, IPageLayout.TOP, (float)0.25, IPageLayout.ID_EDITOR_AREA);
129             relativePartId= JavaUI.ID_PROJECTS_VIEW;
130             relativePos= IPageLayout.RIGHT;
131         }
132         if (shouldShowPackagesView()) {
133             layout.addView(JavaUI.ID_PACKAGES_VIEW, relativePos, (float)0.25, relativePartId);
134             relativePartId= JavaUI.ID_PACKAGES_VIEW;
135             relativePos= IPageLayout.RIGHT;
136         }
137         layout.addView(JavaUI.ID_TYPES_VIEW, relativePos, (float)0.33, relativePartId);
138         layout.addView(JavaUI.ID_MEMBERS_VIEW, IPageLayout.RIGHT, (float)0.50, JavaUI.ID_TYPES_VIEW);
139
140         IPlaceholderFolderLayout placeHolderLeft= layout.createPlaceholderFolder("left", IPageLayout.LEFT, (float)0.25, IPageLayout.ID_EDITOR_AREA); //$NON-NLS-1$
141
placeHolderLeft.addPlaceholder(JavaUI.ID_TYPE_HIERARCHY);
142         placeHolderLeft.addPlaceholder(IPageLayout.ID_OUTLINE);
143         placeHolderLeft.addPlaceholder(JavaUI.ID_PACKAGES);
144         placeHolderLeft.addPlaceholder(IPageLayout.ID_RES_NAV);
145
146
147         IPlaceholderFolderLayout placeHolderBottom= layout.createPlaceholderFolder("bottom", IPageLayout.BOTTOM, (float)0.75, IPageLayout.ID_EDITOR_AREA); //$NON-NLS-1$
148
placeHolderBottom.addPlaceholder(IPageLayout.ID_PROBLEM_VIEW);
149         placeHolderBottom.addPlaceholder(NewSearchUI.SEARCH_VIEW_ID);
150         placeHolderBottom.addPlaceholder(IConsoleConstants.ID_CONSOLE_VIEW);
151         placeHolderBottom.addPlaceholder(IPageLayout.ID_BOOKMARKS);
152         placeHolderBottom.addPlaceholder(JavaUI.ID_SOURCE_VIEW);
153         placeHolderBottom.addPlaceholder(JavaUI.ID_JAVADOC_VIEW);
154         placeHolderBottom.addPlaceholder(IProgressConstants.PROGRESS_VIEW_ID);
155     }
156
157     private boolean shouldShowProjectsView() {
158         return fgJavaElementFromAction == null || fgJavaElementFromAction.getElementType() == IJavaElement.JAVA_MODEL;
159     }
160
161     private boolean shouldShowPackagesView() {
162         if (fgJavaElementFromAction == null)
163             return true;
164         int type= fgJavaElementFromAction.getElementType();
165         return type == IJavaElement.JAVA_MODEL || type == IJavaElement.JAVA_PROJECT || type == IJavaElement.PACKAGE_FRAGMENT_ROOT;
166     }
167
168     private boolean stackBrowsingViewsVertically() {
169         return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.BROWSING_STACK_VERTICALLY);
170     }
171
172     /*
173      * XXX: This is a workaround for: http://dev.eclipse.org/bugs/show_bug.cgi?id=13070
174      */

175     static void setInputFromAction(IAdaptable input) {
176         if (input instanceof IJavaElement)
177             fgJavaElementFromAction= (IJavaElement)input;
178         else
179             fgJavaElementFromAction= null;
180     }
181 }
182
Popular Tags