1 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 32 static IJavaElement fgJavaElementFromAction; 33 34 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 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 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 layout.addShowViewShortcut(NewSearchUI.SEARCH_VIEW_ID); 65 66 layout.addShowViewShortcut(IConsoleConstants.ID_CONSOLE_VIEW); 68 69 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 layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.JavaProjectWizard"); layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewPackageCreationWizard"); layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewClassCreationWizard"); layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewInterfaceCreationWizard"); layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewEnumCreationWizard"); layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewAnnotationCreationWizard"); layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewSourceFolderCreationWizard"); layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewSnippetFileCreationWizard"); layout.addNewWizardShortcut("org.eclipse.ui.wizards.new.folder"); layout.addNewWizardShortcut("org.eclipse.ui.wizards.new.file"); layout.addNewWizardShortcut("org.eclipse.ui.editors.wizards.UntitledTextFileWizard"); } 89 90 private void createVerticalLayout(IPageLayout layout) { 91 String 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); 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); 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 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); 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); 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 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 |