1 11 12 package org.eclipse.pde.internal.ui.editor.build; 13 14 import org.eclipse.core.resources.IFile; 15 import org.eclipse.core.resources.IFolder; 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.runtime.Path; 18 import org.eclipse.pde.core.IModelChangedEvent; 19 import org.eclipse.pde.core.IModelChangedListener; 20 import org.eclipse.pde.core.build.IBuild; 21 import org.eclipse.pde.core.build.IBuildEntry; 22 import org.eclipse.pde.internal.build.IBuildPropertiesConstants; 23 import org.eclipse.pde.internal.ui.PDEUIMessages; 24 import org.eclipse.swt.widgets.Composite; 25 26 public class BinSection extends BuildContentsSection 27 implements 28 IModelChangedListener { 29 30 public BinSection(BuildPage page, Composite parent) { 31 super(page, parent); 32 getSection().setText(PDEUIMessages.BuildEditor_BinSection_title); 33 getSection().setDescription(PDEUIMessages.BuildEditor_BinSection_desc); 34 } 35 36 protected void initializeCheckState() { 37 super.initializeCheckState(); 38 IBuild build = fBuildModel.getBuild(); 39 IBuildEntry binIncl = build 40 .getEntry(IBuildPropertiesConstants.PROPERTY_BIN_INCLUDES); 41 IBuildEntry binExcl = build 42 .getEntry(IBuildPropertiesConstants.PROPERTY_BIN_EXCLUDES); 43 44 if (binIncl == null) 45 return; 46 47 super.initializeCheckState(binIncl, binExcl); 48 } 49 50 protected void deleteFolderChildrenFromEntries(IFolder folder) { 51 IBuild build = fBuildModel.getBuild(); 52 IBuildEntry binIncl = build 53 .getEntry(IBuildPropertiesConstants.PROPERTY_BIN_INCLUDES); 54 IBuildEntry binExcl = build 55 .getEntry(IBuildPropertiesConstants.PROPERTY_BIN_EXCLUDES); 56 String parentFolder = getResourceFolderName(folder 57 .getProjectRelativePath().toString()); 58 59 removeChildren(binIncl, parentFolder); 60 removeChildren(binExcl, parentFolder); 61 } 62 63 protected void handleBuildCheckStateChange(boolean wasTopParentChecked) { 64 IResource resource = fParentResource; 65 String resourceName = fParentResource.getProjectRelativePath() 66 .toString(); 67 IBuild build = fBuildModel.getBuild(); 68 IBuildEntry includes = build 69 .getEntry(IBuildPropertiesConstants.PROPERTY_BIN_INCLUDES); 70 IBuildEntry excludes = build 71 .getEntry(IBuildPropertiesConstants.PROPERTY_BIN_EXCLUDES); 72 73 resourceName = handleResourceFolder(resource, resourceName); 74 75 if (isChecked) 76 handleCheck(includes, excludes, resourceName, resource, 77 wasTopParentChecked, 78 IBuildPropertiesConstants.PROPERTY_BIN_INCLUDES); 79 else 80 handleUncheck(includes, excludes, resourceName, resource, 81 IBuildPropertiesConstants.PROPERTY_BIN_EXCLUDES); 82 83 deleteEmptyEntries(); 84 fParentResource = fOriginalResource = null; 85 } 86 87 public void modelChanged(IModelChangedEvent event) { 88 if (event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) { 89 markStale(); 90 } 91 Object changeObject = event.getChangedObjects()[0]; 92 93 if (!(changeObject instanceof IBuildEntry && (((IBuildEntry) changeObject) 94 .getName().equals( 95 IBuildPropertiesConstants.PROPERTY_BIN_EXCLUDES) || ((IBuildEntry) changeObject) 96 .getName().equals( 97 IBuildPropertiesConstants.PROPERTY_BIN_INCLUDES)))) 98 return; 99 100 if ((fParentResource == null && fOriginalResource != null) 101 || (fOriginalResource == null && fParentResource != null)) { 102 initializeCheckState(); 103 return; 104 } 105 if (fParentResource == null && fOriginalResource == null){ 106 if (event.getChangedProperty() != null && event 107 .getChangedProperty() 108 .equals(IBuildPropertiesConstants.PROPERTY_BIN_INCLUDES)) { 109 110 if (event.getOldValue() == null && event.getNewValue() != null) { 111 if (event.getNewValue().equals(".")) return; 113 IFile file = fProject.getFile(new Path(event.getNewValue() 115 .toString())); 116 if (!file.exists()) 117 return; 118 fParentResource = fOriginalResource = file; 119 isChecked = true; 120 } else if (event.getOldValue() != null 121 && event.getNewValue() == null) { 122 if (event.getOldValue().equals(".")) return; 124 IFile file = fProject.getFile(new Path(event.getOldValue() 126 .toString())); 127 if (!file.exists()) 128 return; 129 fParentResource = fOriginalResource = file; 130 isChecked = false; 131 } else { 132 return; 133 } 134 } 135 return; 136 } 137 fTreeViewer.setChecked(fParentResource, isChecked); 138 fTreeViewer.setGrayed(fOriginalResource, false); 139 fTreeViewer.setParentsGrayed(fParentResource, true); 140 setParentsChecked(fParentResource); 141 fTreeViewer.setGrayed(fParentResource, false); 142 if (fParentResource instanceof IFolder) { 143 fTreeViewer.setSubtreeChecked(fParentResource, isChecked); 144 setChildrenGrayed(fParentResource, false); 145 } 146 while (!fOriginalResource.equals(fParentResource)) { 147 fTreeViewer.setChecked(fOriginalResource, isChecked); 148 fOriginalResource = fOriginalResource.getParent(); 149 } 150 fParentResource = null; 151 fOriginalResource = null; 152 } 153 } 154 | Popular Tags |