1 11 package org.eclipse.ui.dialogs; 12 13 import org.eclipse.core.resources.IProject; 14 import org.eclipse.core.resources.IWorkspace; 15 import org.eclipse.core.resources.ResourcesPlugin; 16 import org.eclipse.jface.viewers.CheckboxTableViewer; 17 import org.eclipse.jface.viewers.IStructuredContentProvider; 18 import org.eclipse.jface.viewers.ViewerComparator; 19 import org.eclipse.jface.wizard.WizardPage; 20 import org.eclipse.swt.SWT; 21 import org.eclipse.swt.graphics.Font; 22 import org.eclipse.swt.graphics.FontData; 23 import org.eclipse.swt.layout.GridData; 24 import org.eclipse.swt.layout.GridLayout; 25 import org.eclipse.swt.widgets.Composite; 26 import org.eclipse.swt.widgets.Control; 27 import org.eclipse.swt.widgets.Label; 28 import org.eclipse.ui.PlatformUI; 29 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; 30 import org.eclipse.ui.internal.ide.IIDEHelpContextIds; 31 import org.eclipse.ui.model.WorkbenchContentProvider; 32 import org.eclipse.ui.model.WorkbenchLabelProvider; 33 34 50 public class WizardNewProjectReferencePage extends WizardPage { 51 private CheckboxTableViewer referenceProjectsViewer; 53 54 private static final String REFERENCED_PROJECTS_TITLE = IDEWorkbenchMessages.WizardNewProjectReferences_title; 55 56 private static final int PROJECT_LIST_MULTIPLIER = 15; 57 58 63 public WizardNewProjectReferencePage(String pageName) { 64 super(pageName); 65 } 66 67 70 public void createControl(Composite parent) { 71 72 Font font = parent.getFont(); 73 74 Composite composite = new Composite(parent, SWT.NONE); 75 composite.setLayout(new GridLayout()); 76 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 77 composite.setFont(font); 78 79 PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, 80 IIDEHelpContextIds.NEW_PROJECT_REFERENCE_WIZARD_PAGE); 81 82 Label referenceLabel = new Label(composite, SWT.NONE); 83 referenceLabel.setText(REFERENCED_PROJECTS_TITLE); 84 referenceLabel.setFont(font); 85 86 referenceProjectsViewer = CheckboxTableViewer.newCheckList(composite, 87 SWT.BORDER); 88 referenceProjectsViewer.getTable().setFont(composite.getFont()); 89 GridData data = new GridData(); 90 data.horizontalAlignment = GridData.FILL; 91 data.grabExcessHorizontalSpace = true; 92 93 data.heightHint = getDefaultFontHeight(referenceProjectsViewer 94 .getTable(), PROJECT_LIST_MULTIPLIER); 95 referenceProjectsViewer.getTable().setLayoutData(data); 96 referenceProjectsViewer.setLabelProvider(WorkbenchLabelProvider 97 .getDecoratingWorkbenchLabelProvider()); 98 referenceProjectsViewer.setContentProvider(getContentProvider()); 99 referenceProjectsViewer.setComparator(new ViewerComparator()); 100 referenceProjectsViewer.setInput(ResourcesPlugin.getWorkspace()); 101 102 setControl(composite); 103 } 104 105 111 protected IStructuredContentProvider getContentProvider() { 112 return new WorkbenchContentProvider() { 113 public Object [] getChildren(Object element) { 114 if (!(element instanceof IWorkspace)) { 115 return new Object [0]; 116 } 117 IProject[] projects = ((IWorkspace) element).getRoot() 118 .getProjects(); 119 return projects == null ? new Object [0] : projects; 120 } 121 }; 122 } 123 124 130 private static int getDefaultFontHeight(Control control, int lines) { 131 FontData[] viewerFontData = control.getFont().getFontData(); 132 int fontHeight = 10; 133 134 if (viewerFontData.length > 0) { 136 fontHeight = viewerFontData[0].getHeight(); 137 } 138 return lines * fontHeight; 139 140 } 141 142 147 public IProject[] getReferencedProjects() { 148 Object [] elements = referenceProjectsViewer.getCheckedElements(); 149 IProject[] projects = new IProject[elements.length]; 150 System.arraycopy(elements, 0, projects, 0, elements.length); 151 return projects; 152 } 153 } 154 | Popular Tags |