Skip to content

Commit

Permalink
bugfix checkboxes in LibraryTableComposite
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrowder committed May 8, 2012
1 parent 98b2187 commit 78e9a00
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 43 deletions.
1 change: 0 additions & 1 deletion PyJDT/src/net/kbserve/pyjdt/PythonPathContributor.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ protected StringBuffer makePaths(ICPEType classpathContainer,
IJavaProject javaProject) {
IProject project = javaProject.getProject();
StringBuffer sb = new StringBuffer();
System.out.println("Making path for:" + classpathContainer.getPath());
if (classpathContainer.isEnabled()) {
sb.append(classpathContainer.getRealPath(project));
boolean first = sb.length() == 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ public void setChildren(Collection<ICPEType> children) {

public void setEnabled(boolean enabled) {
this.enabled = enabled;
for(ICPEType cpeType:getChildren()) {
cpeType.setEnabled(true);
}
}

@Override
Expand Down
29 changes: 15 additions & 14 deletions PyJDT/src/net/kbserve/pyjdt/properties/models/RootContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import net.kbserve.pyjdt.Activator;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
Expand All @@ -31,9 +30,9 @@ public class RootContainer extends CPEAbstractContainer {
private static final Map<IProject, RootContainer> roots = new HashMap<IProject, RootContainer>();
private static final Map<RootContainer, IProject> reverseRoots = new HashMap<RootContainer, IProject>();

protected static IFile getLibrariesXml(IProject project) {
return getWorkingLocation(project).getFile(
Activator.PLUGIN_ID + ".root.prefs");
protected static IPath getLibrariesXml(IProject project) {
return prependWorkspaceLoc(getWorkingLocation(project).getFile(
Activator.PLUGIN_ID + ".root.prefs").getFullPath());
};

protected static IFolder getWorkingLocation(IProject project) {
Expand Down Expand Up @@ -61,8 +60,9 @@ public static synchronized RootContainer getRoot(IProject project) {
if (rc == null) {
NullProgressMonitor npm = new NullProgressMonitor();
npm.beginTask("Loading PyJDT data for " + project.getName(), 100);
File libxml = getLibrariesXml(project).getFullPath().toFile();
File libxml = getLibrariesXml(project).toFile();
if (libxml.exists()) {
System.out.println("Loading from: " + libxml.getAbsolutePath());
npm.subTask("Attempting to load: " + libxml.getAbsolutePath());
npm.internalWorked(5);
try {
Expand All @@ -78,15 +78,15 @@ public void exceptionThrown(Exception e) {
rc = (RootContainer) d.readObject();
npm.internalWorked(85);
} catch (Exception e) {
e.printStackTrace();
}



}
if (rc == null) {
rc = new RootContainer();
npm.internalWorked(65);
}

reverseRoots.put(rc, project);
roots.put(project, rc);
rc.update();
Expand Down Expand Up @@ -125,19 +125,20 @@ public String getRealPath(IProject project) {
}

public static synchronized RootContainer revert(IProject project) {
System.out.println("Reverting PyJDT from " + project);
roots.put(project, null);
reverseRoots.remove(roots.remove(project));
assert !roots.containsKey(project);
return getRoot(project);
}

public synchronized void save() throws CoreException, FileNotFoundException {
IFile loc = getLibrariesXml(reverseRoots.get(this));
System.out.println("xml:" + loc);

try {
IPath path = prependWorkspaceLoc(loc.getFullPath());
IPath path = getLibrariesXml(reverseRoots.get(this));
System.out.println("xml:" + path.toOSString());
path.toFile().getParentFile().mkdirs();
if (loc.exists()) {
loc.delete(true, null);
if (path.toFile().exists()) {
path.toFile().delete();
}
// loc.create(pis, IResource.HIDDEN, null);//TODO: add progress
// monitor
Expand Down
111 changes: 86 additions & 25 deletions PyJDT/src/net/kbserve/pyjdt/properties/view/LibraryTableComposite.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,29 @@ public class LibraryTableComposite extends Composite {
private final class TableSelectionListener implements SelectionListener {
@Override
public void widgetSelected(SelectionEvent arg0) {
System.out.println("Selection: " + arg0.item);
try {
TreeItem tree = (TreeItem) arg0.item;
ICPEType cpc = (ICPEType) tree.getData();
cpc.setEnabled(tree.getChecked());
if (!tree.getChecked()) {
if ((arg0.detail & SWT.CHECK) == SWT.CHECK) {
try {

TreeItem tree = (TreeItem) arg0.item;
ICPEType cpc = (ICPEType) tree.getData();
cpc.setEnabled(tree.getChecked());
System.out.println("Selection: " + arg0.item + " -> "
+ cpc.isEnabled());
TreeItem parentItem = tree.getParentItem();
if (parentItem.getChecked()) {
parentItem.setGrayed(true);
if (!tree.getChecked()) {
if (parentItem.getChecked()) {
parentItem.setGrayed(true);
} else {

}
} else {
tree.setGrayed(false);
}
updateAll(tree, tree.getChecked());
makeChecksConsistentWithChildren();
} catch (ClassCastException e) {
e.printStackTrace();
}

for (TreeItem child : tree.getItems()) {
ICPEType childClasspathContainer = (ICPEType) child
.getData();
child.setChecked(childClasspathContainer
.isEnabled());
}
} catch (ClassCastException e) {
}

}
Expand All @@ -46,6 +50,39 @@ public void widgetDefaultSelected(SelectionEvent arg0) {
}
}

protected void updateAll(TreeItem parent, boolean checked) {
for (TreeItem child : parent.getItems()) {
child.setChecked(checked);
child.setGrayed(false);
updateAll(child, checked);
}
}

/**
*
* @param child
* @return null if checkbox should be gray, true if checked, false if
* unchecked
*/
private Boolean makeChecksConsistentWithChildren(TreeItem item) {
Boolean ret = item.getChecked();
for (TreeItem child : item.getItems()) {
Boolean current = makeChecksConsistentWithChildren(child);
if (current != ret) {
ret = null;
}
}
item.setChecked(!Boolean.FALSE.equals(ret));
item.setGrayed(ret == null);
return ret;
}

private void makeChecksConsistentWithChildren() {
for(TreeItem item: table.getItems()) {
makeChecksConsistentWithChildren(item);
}
}

private IProject project;
private Tree table;
private TableSelectionListener tableSelectionListener;
Expand Down Expand Up @@ -73,34 +110,58 @@ public void pack(boolean changed) {
root.update();
table.clearAll(true);
table.setItemCount(0);
if(tableSelectionListener==null) {
if (tableSelectionListener != null) {
table.removeSelectionListener(tableSelectionListener);
}
setupClasspathInfo(table, root);
makeChecksConsistentWithChildren();
expandAll(table.getItems());
if (tableSelectionListener == null) {
tableSelectionListener = new TableSelectionListener();
table.addSelectionListener(tableSelectionListener);
}
setupClasspathInfo(table, root);
}
table.pack(changed);
super.pack(changed);
}

private void setupClasspathInfo(Tree tree, ICPEType cp) {
private void expandAll(TreeItem[] items) {
for (TreeItem ti : items) {
ti.setExpanded(true);
expandAll(ti.getItems());
}

}

private TreeItem setupClasspathInfo(Tree tree, ICPEType cp) {
if (cp.isAvailable()) {
TreeItem ti = new TreeItem(tree, SWT.NONE);
setUpTreeItem(cp, ti);
for (ICPEType child : cp.getChildren()) {
setupClasspathInfo(ti, child);
}
return populateChildren(cp, ti);
}
return null;
}

private void setupClasspathInfo(TreeItem treeItem, ICPEType cp) {
private TreeItem setupClasspathInfo(TreeItem treeItem, ICPEType cp) {
if (cp.isAvailable()) {
TreeItem ti = new TreeItem(treeItem, SWT.NONE);
setUpTreeItem(cp, ti);
for (ICPEType child : cp.getChildren()) {
setupClasspathInfo(ti, child);
return populateChildren(cp, ti);
}
return null;
}

private TreeItem populateChildren(ICPEType parentClasspath,
TreeItem parentTreeItem) {
for (ICPEType child : parentClasspath.getChildren()) {
setupClasspathInfo(parentTreeItem, child);
if (!parentClasspath.isEnabled() && child.isEnabled()) {
parentTreeItem.setGrayed(true);
} else if (parentClasspath.isEnabled() && !child.isEnabled()) {
parentTreeItem.setGrayed(true);
}
}
return parentTreeItem;
}

private void setUpTreeItem(ICPEType cp, TreeItem checked) {
Expand Down

0 comments on commit 78e9a00

Please sign in to comment.