001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.build;
011:
012: import org.eclipse.core.resources.IFile;
013: import org.eclipse.core.resources.IFolder;
014: import org.eclipse.core.resources.IResource;
015: import org.eclipse.core.runtime.Path;
016: import org.eclipse.pde.core.IModelChangedEvent;
017: import org.eclipse.pde.core.IModelChangedListener;
018: import org.eclipse.pde.core.build.IBuild;
019: import org.eclipse.pde.core.build.IBuildEntry;
020: import org.eclipse.pde.internal.build.IBuildPropertiesConstants;
021: import org.eclipse.pde.internal.ui.PDEUIMessages;
022: import org.eclipse.swt.widgets.Composite;
023:
024: public class BinSection extends BuildContentsSection implements
025: IModelChangedListener {
026:
027: public BinSection(BuildPage page, Composite parent) {
028: super (page, parent);
029: getSection()
030: .setText(PDEUIMessages.BuildEditor_BinSection_title);
031: getSection().setDescription(
032: PDEUIMessages.BuildEditor_BinSection_desc);
033: }
034:
035: protected void initializeCheckState() {
036: super .initializeCheckState();
037: IBuild build = fBuildModel.getBuild();
038: IBuildEntry binIncl = build
039: .getEntry(IBuildPropertiesConstants.PROPERTY_BIN_INCLUDES);
040: IBuildEntry binExcl = build
041: .getEntry(IBuildPropertiesConstants.PROPERTY_BIN_EXCLUDES);
042:
043: if (binIncl == null)
044: return;
045:
046: super .initializeCheckState(binIncl, binExcl);
047: }
048:
049: protected void deleteFolderChildrenFromEntries(IFolder folder) {
050: IBuild build = fBuildModel.getBuild();
051: IBuildEntry binIncl = build
052: .getEntry(IBuildPropertiesConstants.PROPERTY_BIN_INCLUDES);
053: IBuildEntry binExcl = build
054: .getEntry(IBuildPropertiesConstants.PROPERTY_BIN_EXCLUDES);
055: String parentFolder = getResourceFolderName(folder
056: .getProjectRelativePath().toString());
057:
058: removeChildren(binIncl, parentFolder);
059: removeChildren(binExcl, parentFolder);
060: }
061:
062: protected void handleBuildCheckStateChange(
063: boolean wasTopParentChecked) {
064: IResource resource = fParentResource;
065: String resourceName = fParentResource.getProjectRelativePath()
066: .toString();
067: IBuild build = fBuildModel.getBuild();
068: IBuildEntry includes = build
069: .getEntry(IBuildPropertiesConstants.PROPERTY_BIN_INCLUDES);
070: IBuildEntry excludes = build
071: .getEntry(IBuildPropertiesConstants.PROPERTY_BIN_EXCLUDES);
072:
073: resourceName = handleResourceFolder(resource, resourceName);
074:
075: if (isChecked)
076: handleCheck(includes, excludes, resourceName, resource,
077: wasTopParentChecked,
078: IBuildPropertiesConstants.PROPERTY_BIN_INCLUDES);
079: else
080: handleUncheck(includes, excludes, resourceName, resource,
081: IBuildPropertiesConstants.PROPERTY_BIN_EXCLUDES);
082:
083: deleteEmptyEntries();
084: fParentResource = fOriginalResource = null;
085: }
086:
087: public void modelChanged(IModelChangedEvent event) {
088: if (event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
089: markStale();
090: }
091: Object changeObject = event.getChangedObjects()[0];
092:
093: if (!(changeObject instanceof IBuildEntry && (((IBuildEntry) changeObject)
094: .getName()
095: .equals(IBuildPropertiesConstants.PROPERTY_BIN_EXCLUDES) || ((IBuildEntry) changeObject)
096: .getName()
097: .equals(IBuildPropertiesConstants.PROPERTY_BIN_INCLUDES))))
098: return;
099:
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
107: && event
108: .getChangedProperty()
109: .equals(
110: IBuildPropertiesConstants.PROPERTY_BIN_INCLUDES)) {
111:
112: if (event.getOldValue() == null
113: && event.getNewValue() != null) {
114: if (event.getNewValue().equals(".")) //$NON-NLS-1$
115: return;
116: // adding token
117: IFile file = fProject.getFile(new Path(event
118: .getNewValue().toString()));
119: if (!file.exists())
120: return;
121: fParentResource = fOriginalResource = file;
122: isChecked = true;
123: } else if (event.getOldValue() != null
124: && event.getNewValue() == null) {
125: if (event.getOldValue().equals(".")) //$NON-NLS-1$
126: return;
127: // removing token
128: IFile file = fProject.getFile(new Path(event
129: .getOldValue().toString()));
130: if (!file.exists())
131: return;
132: fParentResource = fOriginalResource = file;
133: isChecked = false;
134: } else {
135: return;
136: }
137: }
138: return;
139: }
140: fTreeViewer.setChecked(fParentResource, isChecked);
141: fTreeViewer.setGrayed(fOriginalResource, false);
142: fTreeViewer.setParentsGrayed(fParentResource, true);
143: setParentsChecked(fParentResource);
144: fTreeViewer.setGrayed(fParentResource, false);
145: if (fParentResource instanceof IFolder) {
146: fTreeViewer.setSubtreeChecked(fParentResource, isChecked);
147: setChildrenGrayed(fParentResource, false);
148: }
149: while (!fOriginalResource.equals(fParentResource)) {
150: fTreeViewer.setChecked(fOriginalResource, isChecked);
151: fOriginalResource = fOriginalResource.getParent();
152: }
153: fParentResource = null;
154: fOriginalResource = null;
155: }
156: }
|