1 12 package org.eclipse.team.internal.ui.wizards; 13 14 15 import java.util.ArrayList ; 16 import java.util.Arrays ; 17 18 import org.eclipse.core.resources.IProject; 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.jface.dialogs.Dialog; 21 import org.eclipse.jface.resource.ImageDescriptor; 22 import org.eclipse.jface.viewers.*; 23 import org.eclipse.jface.wizard.IWizardPage; 24 import org.eclipse.jface.wizard.WizardPage; 25 import org.eclipse.swt.SWT; 26 import org.eclipse.swt.events.SelectionAdapter; 27 import org.eclipse.swt.events.SelectionEvent; 28 import org.eclipse.swt.layout.GridData; 29 import org.eclipse.swt.layout.GridLayout; 30 import org.eclipse.swt.widgets.*; 31 import org.eclipse.team.internal.ui.*; 32 import org.eclipse.team.ui.IConfigurationWizard; 33 import org.eclipse.ui.IWorkbench; 34 import org.eclipse.ui.PlatformUI; 35 import org.eclipse.ui.activities.ITriggerPoint; 36 import org.eclipse.ui.activities.WorkbenchActivityHelper; 37 import org.eclipse.ui.model.*; 38 39 45 public class ConfigureProjectWizardMainPage extends WizardPage { 46 private Table table; 47 private Button showAllToggle; 48 private TableViewer viewer; 49 private AdaptableList wizards; 50 private AdaptableList disabledWizards; 51 private IWorkbench workbench; 52 private IProject project; 53 private String description; 54 55 private IConfigurationWizard selectedWizard; 56 57 66 public ConfigureProjectWizardMainPage(String pageName, String title, ImageDescriptor titleImage, AdaptableList wizards, AdaptableList disabledWizards) { 67 this(pageName,title,titleImage,wizards,disabledWizards, TeamUIMessages.ConfigureProjectWizardMainPage_selectRepository); 68 } 69 70 80 public ConfigureProjectWizardMainPage(String pageName, String title, ImageDescriptor titleImage, AdaptableList wizards, AdaptableList disabledWizards, String description) { 81 super(pageName, title, titleImage); 82 this.wizards = wizards; 83 this.disabledWizards = disabledWizards; 84 this.description = description; 85 } 86 87 public IConfigurationWizard getSelectedWizard() { 88 return selectedWizard; 89 } 90 93 public boolean canFlipToNextPage() { 94 return selectedWizard != null && selectedWizard.getPageCount() > 0; 95 } 96 99 public void createControl(Composite parent) { 100 Composite composite = new Composite(parent, SWT.NULL); 101 composite.setLayout(new GridLayout()); 102 composite.setLayoutData(new GridData(GridData.FILL_BOTH)); 103 104 setControl(composite); 105 106 PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.SHARE_PROJECT_PAGE); 108 109 Label label = new Label(composite, SWT.LEFT); 110 label.setText(description); 111 GridData data = new GridData(); 112 data.horizontalAlignment = GridData.FILL; 113 label.setLayoutData(data); 114 115 table = new Table(composite, SWT.SINGLE | SWT.BORDER); 116 data = new GridData(GridData.FILL_BOTH); 117 data.heightHint = table.getItemHeight() * 7; 118 table.setLayoutData(data); 119 viewer = new TableViewer(table); 120 viewer.setContentProvider(new WorkbenchContentProvider()); 121 viewer.setLabelProvider(new WorkbenchLabelProvider()); 122 viewer.addSelectionChangedListener(new ISelectionChangedListener() { 123 public void selectionChanged(SelectionChangedEvent event) { 124 ISelection selection = event.getSelection(); 126 if (selection == null || !(selection instanceof IStructuredSelection)) { 127 selectedWizard = null; 128 setPageComplete(false); 129 return; 130 } 131 IStructuredSelection ss = (IStructuredSelection)selection; 132 if (ss.size() != 1) { 133 selectedWizard = null; 134 setPageComplete(false); 135 return; 136 } 137 ConfigurationWizardElement selectedElement = (ConfigurationWizardElement)ss.getFirstElement(); 138 try { 139 selectedWizard = (IConfigurationWizard)selectedElement.createExecutableExtension(); 140 selectedWizard.init(workbench, project); 141 } catch (CoreException e) { 142 return; 143 } 144 selectedWizard.addPages(); 145 146 setPageComplete(true); 148 } 149 }); 150 viewer.addDoubleClickListener(new IDoubleClickListener() { 151 public void doubleClick(DoubleClickEvent event) { 152 getWizard().getContainer().showPage(getNextPage()); 153 } 154 }); 155 viewer.setComparator(new ViewerComparator() { 156 public int compare(Viewer viewer, Object e1, Object e2) { 157 if (e1 instanceof ConfigurationWizardElement && e2 instanceof ConfigurationWizardElement) { 158 ConfigurationWizardElement wizard1 = (ConfigurationWizardElement) e1; 159 ConfigurationWizardElement wizard2 = (ConfigurationWizardElement) e2; 160 return wizard1.getLabel(wizard1).compareToIgnoreCase(wizard2.getLabel(wizard2)); 161 } 162 return super.compare(viewer, e1, e2); 163 } 164 }); 165 166 if(disabledWizards.size() > 0) { 167 showAllToggle = new Button(composite, SWT.CHECK); 168 showAllToggle.setText(TeamUIMessages.ConfigureProjectWizard_showAll); 169 showAllToggle.addSelectionListener(new SelectionAdapter() { 170 public void widgetSelected(SelectionEvent e) { 171 ArrayList all = new ArrayList (Arrays.asList(wizards.getChildren())); 172 if(showAllToggle.getSelection()) { 173 all.addAll(Arrays.asList(disabledWizards.getChildren())); 174 } 175 viewer.setInput(new AdaptableList(all)); 176 } 177 }); 178 } 179 180 if(wizards.size() == 0 && showAllToggle != null) { 181 showAllToggle.setSelection(true); 182 ArrayList all = new ArrayList (Arrays.asList(wizards.getChildren())); 183 all.addAll(Arrays.asList(disabledWizards.getChildren())); 184 viewer.setInput(new AdaptableList(all)); 185 } else { 186 viewer.setInput(wizards); 187 } 188 Dialog.applyDialogFont(parent); 189 } 190 197 public IWizardPage getNextPage() { 198 if (selectedWizard == null) return null; 199 if(! WorkbenchActivityHelper.allowUseOf(getTriggerPoint(), ((IStructuredSelection)viewer.getSelection()).getFirstElement())) return null; 200 return selectedWizard.getStartingPage(); 201 } 202 203 private ITriggerPoint getTriggerPoint() { 204 return PlatformUI.getWorkbench() 205 .getActivitySupport().getTriggerPointManager() 206 .getTriggerPoint(TeamUIPlugin.TRIGGER_POINT_ID); 207 } 208 209 214 public void setWorkbench(IWorkbench workbench) { 215 this.workbench = workbench; 216 } 217 222 public void setProject(IProject project) { 223 this.project = project; 224 } 225 public void setVisible(boolean visible) { 226 super.setVisible(visible); 227 if (visible) { 228 table.setFocus(); 229 } 230 } 231 } 232 | Popular Tags |