mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Changed the viewer of the Shared Libraries view to TreeViewer.
This commit is contained in:
parent
fa5b091353
commit
3e5548d32c
4 changed files with 147 additions and 162 deletions
|
@ -1,3 +1,9 @@
|
|||
2003-01-21 Mikhail Khodjaiants
|
||||
Changed the viewer of the Shared Libraries view to TreeViewer.
|
||||
* SharedLibrariesView.java
|
||||
* SharedLibrariesViewContentProvider.java
|
||||
* SharedLibrariesViewEventHandler.java
|
||||
|
||||
2003-01-21 Mikhail Khodjaiants
|
||||
|
||||
* src/org/eclipse/cdt/debu/internal/ui/CDTDebugModelPresentation.java
|
||||
|
|
|
@ -7,10 +7,11 @@ package org.eclipse.cdt.debug.internal.ui.views.sharedlibs;
|
|||
|
||||
import org.eclipse.cdt.debug.core.ICSharedLibraryManager;
|
||||
import org.eclipse.cdt.debug.internal.ui.ICDebugHelpContextIds;
|
||||
import org.eclipse.cdt.debug.internal.ui.views.AbstractDebugEventHandler;
|
||||
import org.eclipse.cdt.debug.internal.ui.views.AbstractDebugEventHandlerView;
|
||||
import org.eclipse.cdt.debug.internal.ui.views.IDebugExceptionHandler;
|
||||
import org.eclipse.debug.core.DebugException;
|
||||
import org.eclipse.debug.core.model.IDebugElement;
|
||||
import org.eclipse.debug.ui.AbstractDebugView;
|
||||
import org.eclipse.debug.ui.DebugUITools;
|
||||
import org.eclipse.debug.ui.IDebugModelPresentation;
|
||||
import org.eclipse.debug.ui.IDebugUIConstants;
|
||||
|
@ -21,7 +22,7 @@ import org.eclipse.jface.util.IPropertyChangeListener;
|
|||
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.TableViewer;
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
@ -32,61 +33,24 @@ import org.eclipse.ui.IWorkbenchPart;
|
|||
/**
|
||||
* Enter type comment.
|
||||
*
|
||||
* @since: Jan 16, 2003
|
||||
* @since: Jan 21, 2003
|
||||
*/
|
||||
public class SharedLibrariesView extends AbstractDebugView
|
||||
public class SharedLibrariesView extends AbstractDebugEventHandlerView
|
||||
implements ISelectionListener,
|
||||
IPropertyChangeListener,
|
||||
IDebugExceptionHandler
|
||||
{
|
||||
/**
|
||||
* Event handler for this view
|
||||
*/
|
||||
private SharedLibrariesViewEventHandler fEventHandler;
|
||||
|
||||
/**
|
||||
* The model presentation used as the label provider for the tree viewer.
|
||||
*/
|
||||
private IDebugModelPresentation fModelPresentation;
|
||||
|
||||
/**
|
||||
* Sets the event handler for this view
|
||||
*
|
||||
* @param eventHandler event handler
|
||||
*/
|
||||
protected void setEventHandler( SharedLibrariesViewEventHandler eventHandler )
|
||||
{
|
||||
fEventHandler = eventHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the event handler for this view
|
||||
*
|
||||
* @return The event handler for this view
|
||||
*/
|
||||
protected SharedLibrariesViewEventHandler getEventHandler()
|
||||
{
|
||||
return fEventHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IWorkbenchPart#dispose()
|
||||
*/
|
||||
public void dispose()
|
||||
{
|
||||
super.dispose();
|
||||
if ( getEventHandler() != null )
|
||||
{
|
||||
getEventHandler().dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.debug.ui.AbstractDebugView#createViewer(Composite)
|
||||
*/
|
||||
protected Viewer createViewer( Composite parent )
|
||||
{
|
||||
TableViewer viewer = new TableViewer( parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL );
|
||||
TreeViewer viewer = new TreeViewer( parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL );
|
||||
viewer.setContentProvider( new SharedLibrariesViewContentProvider() );
|
||||
viewer.setLabelProvider( getModelPresentation() );
|
||||
|
||||
|
@ -200,7 +164,7 @@ public class SharedLibrariesView extends AbstractDebugView
|
|||
* @param viewer the viewer associated with this view
|
||||
* @return an event handler
|
||||
*/
|
||||
protected SharedLibrariesViewEventHandler createEventHandler( Viewer viewer )
|
||||
protected AbstractDebugEventHandler createEventHandler( Viewer viewer )
|
||||
{
|
||||
return new SharedLibrariesViewEventHandler( this );
|
||||
}
|
||||
|
|
|
@ -5,27 +5,102 @@
|
|||
*/
|
||||
package org.eclipse.cdt.debug.internal.ui.views.sharedlibs;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.eclipse.cdt.debug.core.ICSharedLibraryManager;
|
||||
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
||||
import org.eclipse.cdt.debug.internal.ui.views.IDebugExceptionHandler;
|
||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
|
||||
/**
|
||||
* Enter type comment.
|
||||
*
|
||||
* @since: Jan 16, 2003
|
||||
* @since: Jan 21, 2003
|
||||
*/
|
||||
public class SharedLibrariesViewContentProvider implements IStructuredContentProvider
|
||||
public class SharedLibrariesViewContentProvider implements ITreeContentProvider
|
||||
{
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(Object)
|
||||
/**
|
||||
* A table that maps children to their parent element
|
||||
* such that this content provider can walk back up the
|
||||
* parent chain (since values do not know their
|
||||
* parent).
|
||||
* Map of <code>IVariable</code> (child) -> <code>IVariable</code> (parent).
|
||||
*/
|
||||
public Object[] getElements( Object parent )
|
||||
private HashMap fParentCache;
|
||||
|
||||
/**
|
||||
* Handler for exceptions as content is retrieved
|
||||
*/
|
||||
private IDebugExceptionHandler fExceptionHandler = null;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for SharedLibrariesViewContentProvider.
|
||||
*/
|
||||
public SharedLibrariesViewContentProvider()
|
||||
{
|
||||
fParentCache = new HashMap( 10 );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(Object)
|
||||
*/
|
||||
public Object[] getChildren( Object parent )
|
||||
{
|
||||
Object[] children = null;
|
||||
if ( parent != null && parent instanceof ICSharedLibraryManager )
|
||||
{
|
||||
children = ((ICSharedLibraryManager)parent).getSharedLibraries();
|
||||
}
|
||||
if ( children != null )
|
||||
{
|
||||
cache( parent, children );
|
||||
return children;
|
||||
}
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Caches the given elememts as children of the given
|
||||
* parent.
|
||||
*
|
||||
* @param parent parent element
|
||||
* @param children children elements
|
||||
*/
|
||||
protected void cache( Object parent, Object[] children )
|
||||
{
|
||||
for ( int i = 0; i < children.length; i++ )
|
||||
{
|
||||
fParentCache.put( children[i], parent );
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(Object)
|
||||
*/
|
||||
public Object getParent( Object element )
|
||||
{
|
||||
return fParentCache.get( element );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(Object)
|
||||
*/
|
||||
public boolean hasChildren( Object parent )
|
||||
{
|
||||
if ( parent != null && parent instanceof ICSharedLibraryManager )
|
||||
{
|
||||
return ((ICSharedLibraryManager)parent).getSharedLibraries();
|
||||
return ( ((ICSharedLibraryManager)parent).getSharedLibraries().length > 0 );
|
||||
}
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(Object)
|
||||
*/
|
||||
public Object[] getElements( Object inputElement )
|
||||
{
|
||||
return getChildren( inputElement );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -33,6 +108,8 @@ public class SharedLibrariesViewContentProvider implements IStructuredContentPro
|
|||
*/
|
||||
public void dispose()
|
||||
{
|
||||
fParentCache = null;
|
||||
setExceptionHandler( null );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -40,5 +117,50 @@ public class SharedLibrariesViewContentProvider implements IStructuredContentPro
|
|||
*/
|
||||
public void inputChanged( Viewer viewer, Object oldInput, Object newInput )
|
||||
{
|
||||
clearCache();
|
||||
}
|
||||
|
||||
protected void clearCache()
|
||||
{
|
||||
if ( fParentCache != null )
|
||||
{
|
||||
fParentCache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the cached parent for the given children
|
||||
*
|
||||
* @param children for which to remove cached parents
|
||||
*/
|
||||
public void removeCache( Object[] children )
|
||||
{
|
||||
if ( fParentCache != null )
|
||||
{
|
||||
for ( int i = 0; i < children.length; i++ )
|
||||
{
|
||||
fParentCache.remove( children[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an exception handler for this content provider.
|
||||
*
|
||||
* @param handler debug exception handler or <code>null</code>
|
||||
*/
|
||||
protected void setExceptionHandler( IDebugExceptionHandler handler )
|
||||
{
|
||||
fExceptionHandler = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the exception handler for this content provider.
|
||||
*
|
||||
* @return debug exception handler or <code>null</code>
|
||||
*/
|
||||
protected IDebugExceptionHandler getExceptionHandler()
|
||||
{
|
||||
return fExceptionHandler;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,56 +6,25 @@
|
|||
package org.eclipse.cdt.debug.internal.ui.views.sharedlibs;
|
||||
|
||||
import org.eclipse.cdt.debug.core.model.ICSharedLibrary;
|
||||
import org.eclipse.cdt.debug.internal.ui.views.AbstractDebugEventHandler;
|
||||
import org.eclipse.debug.core.DebugEvent;
|
||||
import org.eclipse.debug.core.DebugPlugin;
|
||||
import org.eclipse.debug.core.IDebugEventSetListener;
|
||||
import org.eclipse.debug.core.model.IDebugTarget;
|
||||
import org.eclipse.debug.ui.AbstractDebugView;
|
||||
import org.eclipse.jface.viewers.TableViewer;
|
||||
|
||||
/**
|
||||
* Enter type comment.
|
||||
*
|
||||
* @since: Jan 16, 2003
|
||||
* @since: Jan 21, 2003
|
||||
*/
|
||||
public class SharedLibrariesViewEventHandler implements IDebugEventSetListener
|
||||
public class SharedLibrariesViewEventHandler extends AbstractDebugEventHandler
|
||||
{
|
||||
/**
|
||||
* This event handler's view
|
||||
*/
|
||||
private AbstractDebugView fView;
|
||||
|
||||
/**
|
||||
* Constructor for SharedLibrariesViewEventHandler.
|
||||
* @param view
|
||||
*/
|
||||
public SharedLibrariesViewEventHandler( AbstractDebugView view )
|
||||
{
|
||||
setView( view );
|
||||
DebugPlugin.getDefault().addDebugEventListener( this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IDebugEventSetListener#handleDebugEvents(DebugEvent[])
|
||||
*/
|
||||
public void handleDebugEvents( final DebugEvent[] events )
|
||||
{
|
||||
if ( !isAvailable() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
Runnable r = new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
if ( isAvailable() )
|
||||
{
|
||||
doHandleDebugEvents( events );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
getView().asyncExec( r );
|
||||
super( view );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -81,80 +50,4 @@ public class SharedLibrariesViewEventHandler implements IDebugEventSetListener
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the given element in the viewer - must be called in UI thread.
|
||||
*/
|
||||
protected void refresh( Object element )
|
||||
{
|
||||
if ( isAvailable() )
|
||||
{
|
||||
getView().showViewer();
|
||||
getTableViewer().refresh( element );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the viewer - must be called in UI thread.
|
||||
*/
|
||||
public void refresh()
|
||||
{
|
||||
if ( isAvailable() )
|
||||
{
|
||||
getView().showViewer();
|
||||
getTableViewer().refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* De-registers this event handler from the debug model.
|
||||
*/
|
||||
public void dispose()
|
||||
{
|
||||
DebugPlugin plugin = DebugPlugin.getDefault();
|
||||
plugin.removeDebugEventListener( this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the view this event handler is
|
||||
* updating.
|
||||
*
|
||||
* @return debug view
|
||||
*/
|
||||
protected AbstractDebugView getView()
|
||||
{
|
||||
return fView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the view this event handler is updating.
|
||||
*
|
||||
* @param view debug view
|
||||
*/
|
||||
private void setView( AbstractDebugView view )
|
||||
{
|
||||
fView = view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the viewer this event handler is updating.
|
||||
*
|
||||
* @return viewer
|
||||
*/
|
||||
protected TableViewer getTableViewer()
|
||||
{
|
||||
return (TableViewer)getView().getViewer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this event handler's viewer is
|
||||
* currently available.
|
||||
*
|
||||
* @return whether this event handler's viewer is
|
||||
* currently available
|
||||
*/
|
||||
protected boolean isAvailable()
|
||||
{
|
||||
return getView().isAvailable();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue