org.eclipse.jface.preference.PreferenceContentProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spotless-ext-greclipse Show documentation
Show all versions of spotless-ext-greclipse Show documentation
Groovy Eclipse's formatter bundled for Spotless
The newest version!
/*******************************************************************************
* Copyright (c) 2003, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jface.preference;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
/**
* Provides a tree model for PreferenceManager
content.
*
* @since 3.0
*/
public class PreferenceContentProvider implements ITreeContentProvider {
private PreferenceManager manager;
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
@Override
public void dispose() {
manager = null;
}
/**
* Find the parent of the provided node. Will search recursivly through the
* preference tree.
*
* @param parent the possible parent node.
* @param target the target child node.
* @return the parent node of the child node.
*/
private IPreferenceNode findParent(IPreferenceNode parent,
IPreferenceNode target) {
if (parent.getId().equals(target.getId())) {
return null;
}
IPreferenceNode found = parent.findSubNode(target.getId());
if (found != null) {
return parent;
}
IPreferenceNode[] children = parent.getSubNodes();
for (int i = 0; i < children.length; i++) {
found = findParent(children[i], target);
if (found != null) {
return found;
}
}
return null;
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
*/
@Override
public Object[] getChildren(Object parentElement) {//must be an instance of IPreferenceNode
.
return ((IPreferenceNode) parentElement).getSubNodes();
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
@Override
public Object[] getElements(Object inputElement) {// must be an instance of PreferenceManager
.
return getChildren(((PreferenceManager) inputElement).getRoot());
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
*/
@Override
public Object getParent(Object element) {//must be an instance of IPreferenceNode
.
IPreferenceNode targetNode = (IPreferenceNode) element;
IPreferenceNode root = manager.getRoot();
return findParent(root, targetNode);
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
*/
@Override
public boolean hasChildren(Object element) {
return getChildren(element).length > 0;
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
manager = (PreferenceManager) newInput;
}
/**
* Set the manager for the preferences.
* @param manager The manager to set.
*
* @since 3.1
*/
protected void setManager(PreferenceManager manager) {
this.manager = manager;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy