mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix persistence of resource selections in working sets
This commit is contained in:
parent
1c2f9bf300
commit
aaf2089a7e
1 changed files with 62 additions and 57 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2000, 2006 IBM Corporation and others.
|
* Copyright (c) 2000, 2007 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -12,6 +12,8 @@
|
||||||
package org.eclipse.cdt.internal.ui.workingsets;
|
package org.eclipse.cdt.internal.ui.workingsets;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IContainer;
|
import org.eclipse.core.resources.IContainer;
|
||||||
|
@ -59,7 +61,7 @@ import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
|
||||||
import org.eclipse.cdt.internal.ui.viewsupport.DecoratingCLabelProvider;
|
import org.eclipse.cdt.internal.ui.viewsupport.DecoratingCLabelProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The C element working set page allows the user to clreate
|
* The C element working set page allows the user to create
|
||||||
* and edit a C element working set.
|
* and edit a C element working set.
|
||||||
* <p>
|
* <p>
|
||||||
* Working set elements are presented as a C element tree.
|
* Working set elements are presented as a C element tree.
|
||||||
|
@ -186,7 +188,7 @@ public class CElementWorkingSetPage extends WizardPage implements IWorkingSetPag
|
||||||
} else {
|
} else {
|
||||||
// Add inaccessible resources
|
// Add inaccessible resources
|
||||||
IAdaptable[] oldItems= fWorkingSet.getElements();
|
IAdaptable[] oldItems= fWorkingSet.getElements();
|
||||||
ArrayList closedWithChildren= new ArrayList(elements.size());
|
HashSet closedWithChildren= new HashSet(elements.size());
|
||||||
for (int i= 0; i < oldItems.length; i++) {
|
for (int i= 0; i < oldItems.length; i++) {
|
||||||
IResource oldResource= null;
|
IResource oldResource= null;
|
||||||
if (oldItems[i] instanceof IResource) {
|
if (oldItems[i] instanceof IResource) {
|
||||||
|
@ -196,7 +198,7 @@ public class CElementWorkingSetPage extends WizardPage implements IWorkingSetPag
|
||||||
}
|
}
|
||||||
if (oldResource != null && oldResource.isAccessible() == false) {
|
if (oldResource != null && oldResource.isAccessible() == false) {
|
||||||
IProject project= oldResource.getProject();
|
IProject project= oldResource.getProject();
|
||||||
if (elements.contains(project) || closedWithChildren.contains(project)) {
|
if (closedWithChildren.contains(project) || elements.contains(project)) {
|
||||||
elements.add(oldItems[i]);
|
elements.add(oldItems[i]);
|
||||||
elements.remove(project);
|
elements.remove(project);
|
||||||
closedWithChildren.add(project);
|
closedWithChildren.add(project);
|
||||||
|
@ -242,14 +244,44 @@ public class CElementWorkingSetPage extends WizardPage implements IWorkingSetPag
|
||||||
|| element instanceof ICModel || element instanceof IContainer);
|
|| element instanceof ICModel || element instanceof IContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateParentState(Object child, boolean baseChildState) {
|
||||||
|
if (child == null)
|
||||||
|
return;
|
||||||
|
if (child instanceof IAdaptable) {
|
||||||
|
IResource resource= (IResource)((IAdaptable)child).getAdapter(IResource.class);
|
||||||
|
if (resource != null && !resource.isAccessible())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Object parent= fTreeContentProvider.getParent(child);
|
||||||
|
if (parent == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
updateObjectState(parent, baseChildState);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateObjectState(Object element, boolean baseChildState) {
|
||||||
|
|
||||||
|
boolean allSameState= true;
|
||||||
|
Object[] children= fTreeContentProvider.getChildren(element);
|
||||||
|
|
||||||
|
for (int i= children.length -1; i >= 0; i--) {
|
||||||
|
if (fTree.getChecked(children[i]) != baseChildState || fTree.getGrayed(children[i])) {
|
||||||
|
allSameState= false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fTree.setGrayed(element, !allSameState);
|
||||||
|
fTree.setChecked(element, !allSameState || baseChildState);
|
||||||
|
|
||||||
|
updateParentState(element, baseChildState);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the checked state of tree items based on the initial
|
* Sets the checked state of tree items based on the initial
|
||||||
* working set, if any.
|
* working set, if any.
|
||||||
*/
|
*/
|
||||||
private void initializeCheckedState() {
|
private void initializeCheckedState() {
|
||||||
if (fWorkingSet == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {
|
BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
Object[] elements;
|
Object[] elements;
|
||||||
|
@ -281,32 +313,44 @@ public class CElementWorkingSetPage extends WizardPage implements IWorkingSetPag
|
||||||
|
|
||||||
for (int i = 0; i < elements.length; i++) {
|
for (int i = 0; i < elements.length; i++) {
|
||||||
Object element = elements[i];
|
Object element = elements[i];
|
||||||
if (element instanceof IResource) {
|
|
||||||
// for backwards compatibility: adapt to ICElement if possible
|
|
||||||
ICElement cElement= CoreModel.getDefault().create((IResource)element);
|
|
||||||
if (cElement != null) {
|
|
||||||
elements[i]= element= cElement;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (element instanceof IResource) {
|
if (element instanceof IResource) {
|
||||||
IProject project= ((IResource)element).getProject();
|
IProject project= ((IResource)element).getProject();
|
||||||
if (!project.isAccessible())
|
if (!project.isAccessible()) {
|
||||||
elements[i]= project;
|
elements[i]= project;
|
||||||
}
|
} else {
|
||||||
if (element instanceof ICElement) {
|
// for backwards compatibility: adapt to ICElement if possible
|
||||||
|
if(CoreModel.hasCNature(project)) {
|
||||||
|
ICElement cElement= CoreModel.getDefault().create((IResource)element);
|
||||||
|
if (cElement != null) {
|
||||||
|
elements[i]= cElement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (element instanceof ICElement) {
|
||||||
ICProject cProject= ((ICElement)element).getCProject();
|
ICProject cProject= ((ICElement)element).getCProject();
|
||||||
if (cProject != null && !cProject.getProject().isAccessible())
|
if (cProject != null && !cProject.getProject().isAccessible())
|
||||||
elements[i]= cProject.getProject();
|
elements[i]= cProject.getProject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fTree.setCheckedElements(elements);
|
fTree.setCheckedElements(elements);
|
||||||
|
HashSet parents = new HashSet();
|
||||||
for (int i= 0; i < elements.length; i++) {
|
for (int i= 0; i < elements.length; i++) {
|
||||||
Object element= elements[i];
|
Object element= elements[i];
|
||||||
if (isExpandable(element))
|
if (isExpandable(element))
|
||||||
setSubtreeChecked(element, true, true);
|
setSubtreeChecked(element, true, true);
|
||||||
|
|
||||||
updateParentState(element, true);
|
if (element instanceof IAdaptable) {
|
||||||
|
IResource resource= (IResource) ((IAdaptable)element).getAdapter(IResource.class);
|
||||||
|
if (resource != null && !resource.isAccessible())
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Object parent= fTreeContentProvider.getParent(element);
|
||||||
|
if (parent != null)
|
||||||
|
parents.add(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (Iterator i = parents.iterator(); i.hasNext();)
|
||||||
|
updateObjectState(i.next(), true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -356,45 +400,6 @@ public class CElementWorkingSetPage extends WizardPage implements IWorkingSetPag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check and gray the resource parent if all resources of the
|
|
||||||
* parent are checked.
|
|
||||||
*
|
|
||||||
* @param child the resource whose parent checked state should
|
|
||||||
* be set.
|
|
||||||
* @param baseChildState
|
|
||||||
*/
|
|
||||||
void updateParentState(Object child, boolean baseChildState) {
|
|
||||||
if (child == null)
|
|
||||||
return;
|
|
||||||
if (child instanceof IAdaptable) {
|
|
||||||
IResource resource = (IResource) ((IAdaptable) child)
|
|
||||||
.getAdapter(IResource.class);
|
|
||||||
if (resource != null && !resource.isAccessible())
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Object parent = fTreeContentProvider.getParent(child);
|
|
||||||
if (parent == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
boolean allSameState = true;
|
|
||||||
Object[] children = null;
|
|
||||||
children = fTreeContentProvider.getChildren(parent);
|
|
||||||
|
|
||||||
for (int i = children.length - 1; i >= 0; i--) {
|
|
||||||
if (fTree.getChecked(children[i]) != baseChildState
|
|
||||||
|| fTree.getGrayed(children[i])) {
|
|
||||||
allSameState = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fTree.setGrayed(parent, !allSameState);
|
|
||||||
fTree.setChecked(parent, !allSameState || baseChildState);
|
|
||||||
|
|
||||||
updateParentState(parent, baseChildState);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the working set name and the checked state of the
|
* Validates the working set name and the checked state of the
|
||||||
* resource tree.
|
* resource tree.
|
||||||
|
|
Loading…
Add table
Reference in a new issue