1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

ClastCastException when saving 36876

PR 36743  extending cview with new methods
This commit is contained in:
Alain Magloire 2003-04-27 00:18:02 +00:00
parent 1a3542db44
commit 69017e4c59

View file

@ -414,10 +414,10 @@ public class CView extends ViewPart implements IMenuListener, ISetSelectionTarge
*/ */
public void createPartControl (Composite parent) { public void createPartControl (Composite parent) {
viewer= new ProblemTreeViewer (parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); viewer = createViewer(parent);
boolean showCUChildren= CPluginPreferencePage.showCompilationUnitChildren();
viewer.setUseHashlookup (true); viewer.setUseHashlookup (true);
viewer.setContentProvider(new CElementContentProvider (showCUChildren, true)); CElementContentProvider provider = createContentProvider();
viewer.setContentProvider(provider);
setLabelDecorator(PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()); setLabelDecorator(PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator());
CUIPlugin.getDefault().getProblemMarkerManager().addListener(viewer); CUIPlugin.getDefault().getProblemMarkerManager().addListener(viewer);
CUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this); CUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this);
@ -490,6 +490,19 @@ public class CView extends ViewPart implements IMenuListener, ISetSelectionTarge
} }
protected ProblemTreeViewer createViewer(Composite parent) {
return new ProblemTreeViewer (parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
}
protected CElementContentProvider createContentProvider() {
boolean showCUChildren= CPluginPreferencePage.showCompilationUnitChildren();
return new CElementContentProvider(showCUChildren, true);
}
protected StandardCElementLabelProvider createLabelProvider () {
return new StandardCElementLabelProvider();
}
/* (non-Javadoc) /* (non-Javadoc)
* Method declared on IWorkbenchPart. * Method declared on IWorkbenchPart.
*/ */
@ -1088,7 +1101,7 @@ public class CView extends ViewPart implements IMenuListener, ISetSelectionTarge
* @param decorator a label decorator or <code>null</code> for no decorations. * @param decorator a label decorator or <code>null</code> for no decorations.
*/ */
public void setLabelDecorator(ILabelDecorator decorator) { public void setLabelDecorator(ILabelDecorator decorator) {
ILabelProvider cProvider= new StandardCElementLabelProvider(); ILabelProvider cProvider= createLabelProvider();
if (decorator == null) { if (decorator == null) {
viewer.setLabelProvider(cProvider); viewer.setLabelProvider(cProvider);
} else { } else {
@ -1207,10 +1220,11 @@ public class CView extends ViewPart implements IMenuListener, ISetSelectionTarge
if (p != null) { if (p != null) {
IPath path = new Path(p); IPath path = new Path(p);
ICElement element = factory.create(path); ICElement element = factory.create(path);
if (element != null) if (element != null) {
elements.add(element); elements.add(element);
} }
} }
}
viewer.setExpandedElements(elements.toArray()); viewer.setExpandedElements(elements.toArray());
} }
childMem = memento.getChild(TAG_SELECTION); childMem = memento.getChild(TAG_SELECTION);
@ -1222,10 +1236,11 @@ public class CView extends ViewPart implements IMenuListener, ISetSelectionTarge
if (p != null) { if (p != null) {
IPath path = new Path(p); IPath path = new Path(p);
ICElement element = factory.create(path); ICElement element = factory.create(path);
if (element != null) if (element != null) {
list.add(element); list.add(element);
} }
} }
}
viewer.setSelection(new StructuredSelection(list)); viewer.setSelection(new StructuredSelection(list));
} }
@ -1254,9 +1269,10 @@ public class CView extends ViewPart implements IMenuListener, ISetSelectionTarge
} }
public void saveState(IMemento memento) { public void saveState(IMemento memento) {
if(viewer == null) { if (viewer == null) {
if(this.memento != null) //Keep the old state; if (this.memento != null) { //Keep the old state;
memento.putMemento(this.memento); memento.putMemento(this.memento);
}
return; return;
} }
@ -1273,26 +1289,29 @@ public class CView extends ViewPart implements IMenuListener, ISetSelectionTarge
|| o instanceof IBinary || o instanceof IArchive)) { || o instanceof IBinary || o instanceof IArchive)) {
IMemento elementMem = expandedMem.createChild(TAG_ELEMENT); IMemento elementMem = expandedMem.createChild(TAG_ELEMENT);
ICElement e = (ICElement)o; ICElement e = (ICElement)o;
IResource res = (IResource)e.getAdapter(IResource.class); IResource res = e.getResource();
if (res != null) if (res != null) {
elementMem.putString(TAG_PATH, res.getLocation().toOSString()); elementMem.putString(TAG_PATH, res.getLocation().toOSString());
} }
} }
} }
}
//save selection //save selection
Object elements[] = ((IStructuredSelection)viewer.getSelection()).toArray(); Object elements[] = ((IStructuredSelection)viewer.getSelection()).toArray();
if(elements.length > 0) { if(elements.length > 0) {
IMemento selectionMem = memento.createChild(TAG_SELECTION); IMemento selectionMem = memento.createChild(TAG_SELECTION);
for (int i = 0; i < elements.length; i++) { for (int i = 0; i < elements.length; i++) {
if (elements[i] instanceof ICElement) {
ICElement e = (ICElement)elements[i]; ICElement e = (ICElement)elements[i];
IResource r = (IResource)e.getAdapter(IResource.class); IResource r = e.getResource();
if (r != null) { if (r != null) {
IMemento elementMem = selectionMem.createChild(TAG_ELEMENT); IMemento elementMem = selectionMem.createChild(TAG_ELEMENT);
elementMem.putString(TAG_PATH,r.getLocation().toString()); elementMem.putString(TAG_PATH,r.getLocation().toString());
} }
} }
} }
}
//save vertical position //save vertical position
ScrollBar bar = tree.getVerticalBar(); ScrollBar bar = tree.getVerticalBar();