]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2010 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 | ||
15 | import org.eclipse.ui.IPageLayout; | |
16 | import org.eclipse.ui.IPerspectiveFactory; | |
17 | import org.eclipse.ui.IPlaceholderFolderLayout; | |
18 | import org.eclipse.ui.console.IConsoleConstants; | |
19 | import org.eclipse.ui.progress.IProgressConstants; | |
20 | ||
21 | import org.eclipse.ui.texteditor.templates.TemplatesView; | |
22 | ||
23 | import org.eclipse.debug.ui.IDebugUIConstants; | |
24 | ||
25 | import org.eclipse.search.ui.NewSearchUI; | |
26 | ||
27 | import org.eclipse.jdt.core.IJavaElement; | |
28 | ||
29 | import org.eclipse.jdt.ui.JavaUI; | |
30 | import org.eclipse.jdt.ui.PreferenceConstants; | |
31 | ||
32 | import org.eclipse.jdt.internal.ui.JavaPlugin; | |
33 | ||
34 | ||
35 | public class JavaBrowsingPerspectiveFactory implements IPerspectiveFactory { | |
36 | ||
37 | /* | |
38 | * XXX: This is a workaround for: http://dev.eclipse.org/bugs/show_bug.cgi?id=13070 | |
39 | */ | |
40 | static IJavaElement fgJavaElementFromAction; | |
41 | ||
42 | /** | |
43 | * Constructs a new Default layout engine. | |
44 | */ | |
45 | public JavaBrowsingPerspectiveFactory() { | |
46 | super(); | |
47 | } | |
48 | ||
49 | public void createInitialLayout(IPageLayout layout) { | |
50 | if (stackBrowsingViewsVertically()) | |
51 | createVerticalLayout(layout); | |
52 | else | |
53 | createHorizontalLayout(layout); | |
54 | ||
55 | // action sets | |
56 | layout.addActionSet(IDebugUIConstants.LAUNCH_ACTION_SET); | |
57 | layout.addActionSet(JavaUI.ID_ACTION_SET); | |
58 | layout.addActionSet(JavaUI.ID_ELEMENT_CREATION_ACTION_SET); | |
59 | layout.addActionSet(IPageLayout.ID_NAVIGATE_ACTION_SET); | |
60 | ||
61 | // views - java | |
62 | layout.addShowViewShortcut(JavaUI.ID_TYPE_HIERARCHY); | |
63 | layout.addShowViewShortcut(JavaUI.ID_PACKAGES); | |
64 | layout.addShowViewShortcut(JavaUI.ID_PROJECTS_VIEW); | |
65 | layout.addShowViewShortcut(JavaUI.ID_PACKAGES_VIEW); | |
66 | layout.addShowViewShortcut(JavaUI.ID_TYPES_VIEW); | |
67 | layout.addShowViewShortcut(JavaUI.ID_MEMBERS_VIEW); | |
68 | layout.addShowViewShortcut(JavaUI.ID_SOURCE_VIEW); | |
69 | layout.addShowViewShortcut(JavaUI.ID_JAVADOC_VIEW); | |
70 | layout.addShowViewShortcut(TemplatesView.ID); | |
71 | ||
72 | // views - search | |
73 | layout.addShowViewShortcut(NewSearchUI.SEARCH_VIEW_ID); | |
74 | ||
75 | // views - debugging | |
76 | layout.addShowViewShortcut(IConsoleConstants.ID_CONSOLE_VIEW); | |
77 | ||
78 | // views - standard workbench | |
79 | layout.addShowViewShortcut(IPageLayout.ID_OUTLINE); | |
80 | layout.addShowViewShortcut(IPageLayout.ID_PROBLEM_VIEW); | |
81 | layout.addShowViewShortcut(JavaPlugin.ID_RES_NAV); | |
82 | layout.addShowViewShortcut(IPageLayout.ID_TASK_LIST); | |
83 | layout.addShowViewShortcut(IProgressConstants.PROGRESS_VIEW_ID); | |
84 | layout.addShowViewShortcut(IPageLayout.ID_PROJECT_EXPLORER); | |
85 | layout.addShowViewShortcut("org.eclipse.pde.runtime.LogView"); //$NON-NLS-1$ | |
86 | ||
87 | // new actions - Java project creation wizard | |
88 | layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.JavaProjectWizard"); //$NON-NLS-1$ | |
89 | layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewPackageCreationWizard"); //$NON-NLS-1$ | |
90 | layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewClassCreationWizard"); //$NON-NLS-1$ | |
91 | layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewInterfaceCreationWizard"); //$NON-NLS-1$ | |
92 | layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewEnumCreationWizard"); //$NON-NLS-1$ | |
93 | layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewAnnotationCreationWizard"); //$NON-NLS-1$ | |
94 | layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewSourceFolderCreationWizard"); //$NON-NLS-1$ | |
95 | layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewSnippetFileCreationWizard"); //$NON-NLS-1$ | |
96 | layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewJavaWorkingSetWizard"); //$NON-NLS-1$ | |
97 | layout.addNewWizardShortcut("org.eclipse.ui.wizards.new.folder");//$NON-NLS-1$ | |
98 | layout.addNewWizardShortcut("org.eclipse.ui.wizards.new.file");//$NON-NLS-1$ | |
99 | layout.addNewWizardShortcut("org.eclipse.ui.editors.wizards.UntitledTextFileWizard");//$NON-NLS-1$ | |
100 | ||
101 | // 'Window' > 'Open Perspective' contributions | |
102 | layout.addPerspectiveShortcut(JavaUI.ID_PERSPECTIVE); | |
103 | layout.addPerspectiveShortcut(IDebugUIConstants.ID_DEBUG_PERSPECTIVE); | |
104 | ||
105 | } | |
106 | ||
107 | private void createVerticalLayout(IPageLayout layout) { | |
108 | String relativePartId= IPageLayout.ID_EDITOR_AREA; | |
109 | int relativePos= IPageLayout.LEFT; | |
110 | ||
111 | IPlaceholderFolderLayout placeHolderLeft= layout.createPlaceholderFolder("left", IPageLayout.LEFT, (float)0.25, IPageLayout.ID_EDITOR_AREA); //$NON-NLS-1$ | |
112 | placeHolderLeft.addPlaceholder(JavaUI.ID_TYPE_HIERARCHY); | |
113 | placeHolderLeft.addPlaceholder(IPageLayout.ID_OUTLINE); | |
114 | placeHolderLeft.addPlaceholder(JavaUI.ID_PACKAGES); | |
115 | placeHolderLeft.addPlaceholder(JavaPlugin.ID_RES_NAV); | |
116 | placeHolderLeft.addPlaceholder(IPageLayout.ID_PROJECT_EXPLORER); | |
117 | ||
118 | if (shouldShowProjectsView()) { | |
119 | layout.addView(JavaUI.ID_PROJECTS_VIEW, IPageLayout.LEFT, (float)0.25, IPageLayout.ID_EDITOR_AREA); | |
120 | relativePartId= JavaUI.ID_PROJECTS_VIEW; | |
121 | relativePos= IPageLayout.BOTTOM; | |
122 | } | |
123 | if (shouldShowPackagesView()) { | |
124 | layout.addView(JavaUI.ID_PACKAGES_VIEW, relativePos, (float)0.25, relativePartId); | |
125 | relativePartId= JavaUI.ID_PACKAGES_VIEW; | |
126 | relativePos= IPageLayout.BOTTOM; | |
127 | } | |
128 | layout.addView(JavaUI.ID_TYPES_VIEW, relativePos, (float)0.33, relativePartId); | |
129 | layout.addView(JavaUI.ID_MEMBERS_VIEW, IPageLayout.BOTTOM, (float)0.50, JavaUI.ID_TYPES_VIEW); | |
130 | ||
131 | IPlaceholderFolderLayout placeHolderBottom= layout.createPlaceholderFolder("bottom", IPageLayout.BOTTOM, (float)0.75, IPageLayout.ID_EDITOR_AREA); //$NON-NLS-1$ | |
132 | placeHolderBottom.addPlaceholder(IPageLayout.ID_PROBLEM_VIEW); | |
133 | placeHolderBottom.addPlaceholder(NewSearchUI.SEARCH_VIEW_ID); | |
134 | placeHolderBottom.addPlaceholder(IConsoleConstants.ID_CONSOLE_VIEW); | |
135 | placeHolderBottom.addPlaceholder(IPageLayout.ID_BOOKMARKS); | |
136 | placeHolderBottom.addPlaceholder(JavaUI.ID_SOURCE_VIEW); | |
137 | placeHolderBottom.addPlaceholder(JavaUI.ID_JAVADOC_VIEW); | |
138 | placeHolderBottom.addPlaceholder(IProgressConstants.PROGRESS_VIEW_ID); | |
139 | } | |
140 | ||
141 | private void createHorizontalLayout(IPageLayout layout) { | |
142 | String relativePartId= IPageLayout.ID_EDITOR_AREA; | |
143 | int relativePos= IPageLayout.TOP; | |
144 | ||
145 | if (shouldShowProjectsView()) { | |
146 | layout.addView(JavaUI.ID_PROJECTS_VIEW, IPageLayout.TOP, (float)0.25, IPageLayout.ID_EDITOR_AREA); | |
147 | relativePartId= JavaUI.ID_PROJECTS_VIEW; | |
148 | relativePos= IPageLayout.RIGHT; | |
149 | } | |
150 | if (shouldShowPackagesView()) { | |
151 | layout.addView(JavaUI.ID_PACKAGES_VIEW, relativePos, (float)0.25, relativePartId); | |
152 | relativePartId= JavaUI.ID_PACKAGES_VIEW; | |
153 | relativePos= IPageLayout.RIGHT; | |
154 | } | |
155 | layout.addView(JavaUI.ID_TYPES_VIEW, relativePos, (float)0.33, relativePartId); | |
156 | layout.addView(JavaUI.ID_MEMBERS_VIEW, IPageLayout.RIGHT, (float)0.50, JavaUI.ID_TYPES_VIEW); | |
157 | ||
158 | IPlaceholderFolderLayout placeHolderLeft= layout.createPlaceholderFolder("left", IPageLayout.LEFT, (float)0.25, IPageLayout.ID_EDITOR_AREA); //$NON-NLS-1$ | |
159 | placeHolderLeft.addPlaceholder(JavaUI.ID_TYPE_HIERARCHY); | |
160 | placeHolderLeft.addPlaceholder(IPageLayout.ID_OUTLINE); | |
161 | placeHolderLeft.addPlaceholder(JavaUI.ID_PACKAGES); | |
162 | placeHolderLeft.addPlaceholder(JavaPlugin.ID_RES_NAV); | |
163 | placeHolderLeft.addPlaceholder(IPageLayout.ID_PROJECT_EXPLORER); | |
164 | ||
165 | ||
166 | IPlaceholderFolderLayout placeHolderBottom= layout.createPlaceholderFolder("bottom", IPageLayout.BOTTOM, (float)0.75, IPageLayout.ID_EDITOR_AREA); //$NON-NLS-1$ | |
167 | placeHolderBottom.addPlaceholder(IPageLayout.ID_PROBLEM_VIEW); | |
168 | placeHolderBottom.addPlaceholder(NewSearchUI.SEARCH_VIEW_ID); | |
169 | placeHolderBottom.addPlaceholder(IConsoleConstants.ID_CONSOLE_VIEW); | |
170 | placeHolderBottom.addPlaceholder(IPageLayout.ID_BOOKMARKS); | |
171 | placeHolderBottom.addPlaceholder(JavaUI.ID_SOURCE_VIEW); | |
172 | placeHolderBottom.addPlaceholder(JavaUI.ID_JAVADOC_VIEW); | |
173 | placeHolderBottom.addPlaceholder(IProgressConstants.PROGRESS_VIEW_ID); | |
174 | } | |
175 | ||
176 | private boolean shouldShowProjectsView() { | |
177 | return fgJavaElementFromAction == null || fgJavaElementFromAction.getElementType() == IJavaElement.JAVA_MODEL; | |
178 | } | |
179 | ||
180 | private boolean shouldShowPackagesView() { | |
181 | if (fgJavaElementFromAction == null) | |
182 | return true; | |
183 | int type= fgJavaElementFromAction.getElementType(); | |
184 | return type == IJavaElement.JAVA_MODEL || type == IJavaElement.JAVA_PROJECT || type == IJavaElement.PACKAGE_FRAGMENT_ROOT; | |
185 | } | |
186 | ||
187 | private boolean stackBrowsingViewsVertically() { | |
188 | return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.BROWSING_STACK_VERTICALLY); | |
189 | } | |
190 | ||
191 | /* | |
192 | * XXX: This is a workaround for: http://dev.eclipse.org/bugs/show_bug.cgi?id=13070 | |
193 | */ | |
194 | static void setInputFromAction(IAdaptable input) { | |
195 | if (input instanceof IJavaElement) | |
196 | fgJavaElementFromAction= (IJavaElement)input; | |
197 | else | |
198 | fgJavaElementFromAction= null; | |
199 | } | |
200 | } |