use of org.eclipse.ui.Saveable in project polymap4-core by Polymap4.
the class NavigatorSaveablesService method getActiveSaveablesFromTreePathProvider.
/**
* @param selection
* @param provider
* @return the active saveables
*/
private Saveable[] getActiveSaveablesFromTreePathProvider(IStructuredSelection selection, ITreePathContentProvider provider) {
Set result = new HashSet();
for (Iterator it = selection.iterator(); it.hasNext(); ) {
Object element = it.next();
Saveable saveable = getSaveable(element);
if (saveable != null) {
result.add(saveable);
} else {
TreePath[] paths = provider.getParents(element);
saveable = findSaveable(paths);
if (saveable != null) {
result.add(saveable);
}
}
}
return (Saveable[]) result.toArray(new Saveable[result.size()]);
}
use of org.eclipse.ui.Saveable in project polymap4-core by Polymap4.
the class NavigatorSaveablesService method computeSaveables.
/**
* helper to compute the saveables for which elements are part of the tree.
* Must be called from a synchronized method.
*
* @return the saveables
*/
private Saveable[] computeSaveables() {
ITreeContentProvider contentProvider = (ITreeContentProvider) viewer.getContentProvider();
boolean isTreepathContentProvider = contentProvider instanceof ITreePathContentProvider;
Object viewerInput = viewer.getInput();
List result = new ArrayList();
Set roots = new HashSet(Arrays.asList(contentProvider.getElements(viewerInput)));
SaveablesProvider[] saveablesProviders = getSaveablesProviders();
for (int i = 0; i < saveablesProviders.length; i++) {
SaveablesProvider saveablesProvider = saveablesProviders[i];
Saveable[] saveables = saveablesProvider.getSaveables();
for (int j = 0; j < saveables.length; j++) {
Saveable saveable = saveables[j];
Object[] elements = saveablesProvider.getElements(saveable);
// the saveable is added to the result if at least one of the
// elements representing the saveable appears in the tree, i.e.
// if its parent chain leads to a root node.
boolean foundRoot = false;
for (int k = 0; !foundRoot && k < elements.length; k++) {
Object element = elements[k];
if (roots.contains(element)) {
result.add(saveable);
foundRoot = true;
} else if (isTreepathContentProvider) {
ITreePathContentProvider treePathContentProvider = (ITreePathContentProvider) contentProvider;
TreePath[] parentPaths = treePathContentProvider.getParents(element);
for (int l = 0; !foundRoot && l < parentPaths.length; l++) {
TreePath parentPath = parentPaths[l];
for (int m = 0; !foundRoot && m < parentPath.getSegmentCount(); m++) {
if (roots.contains(parentPath.getSegment(m))) {
result.add(saveable);
foundRoot = true;
}
}
}
} else {
while (!foundRoot && element != null) {
if (roots.contains(element)) {
// found a parent chain leading to a root. The
// saveable is part of the tree.
result.add(saveable);
foundRoot = true;
} else {
element = contentProvider.getParent(element);
}
}
}
}
}
}
return (Saveable[]) result.toArray(new Saveable[result.size()]);
}
use of org.eclipse.ui.Saveable in project polymap4-core by Polymap4.
the class NavigatorSaveablesService method recomputeSaveablesAndNotify.
private void recomputeSaveablesAndNotify(boolean recomputeProviders, String startedBundleIdOrNull) {
if (recomputeProviders && startedBundleIdOrNull == null && saveablesProviders != null) {
// TODO optimize this
for (int i = 0; i < saveablesProviders.length; i++) {
saveablesProviders[i].dispose();
}
saveablesProviders = null;
} else if (startedBundleIdOrNull != null) {
if (inactivePluginsWithSaveablesProviders.containsKey(startedBundleIdOrNull)) {
updateSaveablesProviders(startedBundleIdOrNull);
}
}
Set oldSaveables = new HashSet(Arrays.asList(currentSaveables));
currentSaveables = computeSaveables();
Set newSaveables = new HashSet(Arrays.asList(currentSaveables));
final Set removedSaveables = new HashSet(oldSaveables);
removedSaveables.removeAll(newSaveables);
final Set addedSaveables = new HashSet(newSaveables);
addedSaveables.removeAll(oldSaveables);
if (addedSaveables.size() > 0) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (isDisposed()) {
return;
}
outsideListener.handleLifecycleEvent(new SaveablesLifecycleEvent(saveablesSource, SaveablesLifecycleEvent.POST_OPEN, (Saveable[]) addedSaveables.toArray(new Saveable[addedSaveables.size()]), false));
}
});
}
// an appropriate PRE_CLOSE
if (removedSaveables.size() > 0) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (isDisposed()) {
return;
}
outsideListener.handleLifecycleEvent(new SaveablesLifecycleEvent(saveablesSource, SaveablesLifecycleEvent.PRE_CLOSE, (Saveable[]) removedSaveables.toArray(new Saveable[removedSaveables.size()]), true));
outsideListener.handleLifecycleEvent(new SaveablesLifecycleEvent(saveablesSource, SaveablesLifecycleEvent.POST_CLOSE, (Saveable[]) removedSaveables.toArray(new Saveable[removedSaveables.size()]), false));
}
});
}
}
Aggregations