1 13 package org.eclipse.ui.internal.ide.dialogs; 14 15 import java.util.ArrayList ; 16 17 import org.eclipse.core.resources.IProject; 18 import org.eclipse.core.resources.IResource; 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.core.runtime.IStatus; 21 import org.eclipse.jface.dialogs.ErrorDialog; 22 import org.eclipse.swt.SWT; 23 import org.eclipse.swt.widgets.Composite; 24 import org.eclipse.swt.widgets.Control; 25 import org.eclipse.swt.widgets.Label; 26 import org.eclipse.ui.PlatformUI; 27 import org.eclipse.ui.dialogs.PropertyPage; 28 import org.eclipse.ui.internal.ide.Category; 29 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; 30 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 31 import org.eclipse.ui.internal.ide.IIDEHelpContextIds; 32 import org.eclipse.ui.internal.ide.misc.ProjectCapabilitySelectionGroup; 33 import org.eclipse.ui.internal.ide.registry.Capability; 34 import org.eclipse.ui.internal.ide.registry.CapabilityRegistry; 35 36 40 public class ProjectCapabilityPropertyPage extends PropertyPage { 41 44 private static final int SIZING_WIZARD_WIDTH = 500; 45 46 49 private static final int SIZING_WIZARD_HEIGHT = 500; 50 51 private IProject project; 52 53 private ProjectCapabilitySelectionGroup capabilityGroup; 54 55 58 public ProjectCapabilityPropertyPage() { 59 super(); 60 } 61 62 65 protected Control createContents(Composite parent) { 66 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), 67 IIDEHelpContextIds.PROJECT_CAPABILITY_PROPERTY_PAGE); 68 noDefaultAndApplyButton(); 69 CapabilityRegistry reg = IDEWorkbenchPlugin.getDefault() 70 .getCapabilityRegistry(); 71 72 String instructions; 73 if (reg.hasCapabilities()) 74 instructions = IDEWorkbenchMessages.ProjectCapabilityPropertyPage_chooseCapabilities; 75 else 76 instructions = IDEWorkbenchMessages.ProjectCapabilityPropertyPage_noCapabilities; 77 Label label = new Label(parent, SWT.LEFT); 78 label.setFont(parent.getFont()); 79 label.setText(instructions); 80 81 Capability[] caps = reg.getProjectCapabilities(getProject()); 82 Capability[] disabledCaps = reg 83 .getProjectDisabledCapabilities(getProject()); 84 Category[] cats = new Category[0]; 85 capabilityGroup = new ProjectCapabilitySelectionGroup(cats, caps, 86 disabledCaps, reg); 87 return capabilityGroup.createContents(parent); 88 } 89 90 95 IProject getProject() { 96 if (project == null) 97 project = (IProject) getElement().getAdapter(IResource.class); 98 99 return project; 100 } 101 102 105 public boolean performOk() { 106 if (!capabilityGroup.getCapabilitiesModified()) 108 return true; 109 110 CapabilityRegistry reg = IDEWorkbenchPlugin.getDefault() 112 .getCapabilityRegistry(); 113 Capability[] caps = capabilityGroup.getSelectedCapabilities(); 114 IStatus status = reg.validateCapabilities(caps); 115 if (!status.isOK()) { 116 ErrorDialog 117 .openError( 118 getShell(), 119 IDEWorkbenchMessages.ProjectCapabilityPropertyPage_errorTitle, 120 IDEWorkbenchMessages.ProjectCapabilityPropertyPage_invalidSelection, 121 status); 122 return true; 123 } 124 125 String [] natureIds; 127 try { 128 natureIds = getProject().getDescription().getNatureIds(); 129 natureIds = getProject().getWorkspace().sortNatureSet(natureIds); 130 } catch (CoreException e) { 131 ErrorDialog 132 .openError( 133 getShell(), 134 IDEWorkbenchMessages.ProjectCapabilityPropertyPage_errorTitle, 135 IDEWorkbenchMessages.ProjectCapabilityPropertyPage_internalError, 136 e.getStatus()); 137 return true; 138 } 139 140 ArrayList keepIds = new ArrayList (); 142 ArrayList removeCaps = new ArrayList (); 143 for (int i = 0; i < natureIds.length; i++) { 144 boolean isRemoved = true; 145 String id = natureIds[i]; 146 for (int j = 0; j < caps.length; j++) { 147 if (id.equals(caps[j].getNatureId())) { 148 keepIds.add(id); 149 isRemoved = false; 150 break; 151 } 152 } 153 if (isRemoved) 154 removeCaps.add(reg.getCapabilityForNature(id)); 155 } 156 157 ArrayList newCaps = new ArrayList (); 159 for (int i = 0; i < caps.length; i++) { 160 boolean isNew = true; 161 Capability cap = caps[i]; 162 for (int j = 0; j < natureIds.length; j++) { 163 if (natureIds[j].equals(cap.getNatureId())) { 164 isNew = false; 165 break; 166 } 167 } 168 if (isNew) 169 newCaps.add(cap); 170 } 171 172 if (newCaps.size() > 0 || removeCaps.size() > 0) { 174 Capability[] newCapabilities = new Capability[newCaps.size()]; 175 newCaps.toArray(newCapabilities); 176 177 Capability[] removeCapabilities = new Capability[removeCaps.size()]; 178 removeCaps.toArray(removeCapabilities); 179 180 UpdateProjectCapabilityWizard wizard = new UpdateProjectCapabilityWizard( 181 getProject(), newCapabilities, removeCapabilities); 182 183 MultiStepWizardDialog dialog = new MultiStepWizardDialog( 184 getShell(), wizard); 185 dialog.create(); 186 dialog.getShell().setSize( 187 Math 188 .max(SIZING_WIZARD_WIDTH, dialog.getShell() 189 .getSize().x), SIZING_WIZARD_HEIGHT); 190 PlatformUI.getWorkbench().getHelpSystem().setHelp( 191 dialog.getShell(), 192 IIDEHelpContextIds.UPDATE_CAPABILITY_WIZARD); 193 dialog.open(); 194 } 195 196 return true; 197 } 198 } 199 | Popular Tags |