Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
<copyright> Copyright (c) 2006, 2008 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 - Initial API and implementation Mario Winterer - 225068 Memory leak in part listener management </copyright> $Id: ActionWrapperHelper.java,v 1.3 2008/04/07 12:58:38 cdamus Exp $
 
 package org.eclipse.emf.workspace.ui.actions;
 
 import java.util.Map;
 
 import  org.eclipse.swt.widgets.Event;
Helper object for the undo and redo action wrappers, to share common behaviour that they cannot inherit because they must separately extend the EMF action classes. i.e., this is an instance of the "prefer composition over inheritance" idiom.

Parameters:
<T> the operation-history action handler type that I support
Author(s):
Christian W. Damus (cdamus)
 
 	private final OwnerAccess<T> ownerAccess;
 	
 	private T delegate;
 	
 	private final Map<IWorkbenchPartSite, T> siteToActionHandler =
 	
 		public void propertyChange(PropertyChangeEvent event) {
 			// propagate to my owner's listeners
 					event.getProperty(), event.getOldValue(), event.getNewValue());
 		}};
 
 	ActionWrapperHelper(OwnerAccess<T> ownerAccess) {
 		this. = ownerAccess;
 	}

Extends the superclass implementation to update the operation history undo action handler to which I delegate.
 
 	void setActiveWorkbenchPart(IWorkbenchPart workbenchPart) {
 		IUndoContext context = null;
 		
 		if (workbenchPart != null) {
 			context = (IUndoContextworkbenchPart.getAdapter(IUndoContext.class);
 		}
 		
 		if (context != null) {
 			if ( != null) {
 			}
 			
 			 = getActionHandler(workbenchPart.getSite(), context);
 			
 			// force enablement update in UI
 			boolean enabled = isEnabled();
 					Boolean.valueOf(!enabled),
 					Boolean.valueOf(enabled));
 		}
 	}
 	
 	private T getActionHandler(IWorkbenchPartSite siteIUndoContext context) {
 		T result = .get(site);
 		
 		if (result == null) {
 			result = createActionHandler(sitecontext);
 		}
 		
 		return result;
	}

Creates and returns a action handler for the given workbench-site with the given undo context. The created action handler will be stored in the siteToActionHandler map for further use.

Parameters:
site The site to create an action handler for.
context The undo context the action handler should use.
Returns:
the new action handler
	private T createActionHandler(IWorkbenchPartSite siteIUndoContext context) {
result = .createDelegate(sitecontext);
		if (!actionHandlerExists(site.getPage())) {
			// there are no handlers for the given page so far;
			// one will be added below so we must listen to closing parts
			// on this page to update the siteToActionHandler map.
		}
		.put(siteresult);
		return result;
	}

Removes the action handler for the given workbench-site (if existing) from the site to action-handler map.

Parameters:
site the part site from which to remove the action handler
	private void removeActionHandler(IWorkbenchPartSite site) {
handler = .get(site);
		if (handler != null) {
			if (!actionHandlerExists(site.getPage())) {
				// no more action handler => we do not need to listen to part
				// changes
			}
			// don't dispose the handler, because it's listening for the
			// part closures, too
		}
	}

Tests if there is a mapping to an action handler for any part of the given page.

Parameters:
page a workbench page
Returns:
whether this page currently has any action handler
	private boolean actionHandlerExists(IWorkbenchPage page) {
			if (site.getPage() == page) {
				return true;
			}
		}
		return false;
	}
	private void enablePartListener(IWorkbenchPage page) {
		// according to javadoc of addPartListener, the part listener will not
		// be added twice.
	}
	private void disablePartListener(IWorkbenchPage page) {
	}

Obtains a part listener that will remove the mapping of part-site to action handler when a part is closed.

Returns:
my part listener
		if ( == null) {
				public void partClosed(IWorkbenchPart part) {
				}
				public void partOpened(IWorkbenchPart part) {
					// not interesting
				}
				public void partDeactivated(IWorkbenchPart part) {
					// not interesting
				}
				public void partBroughtToTop(IWorkbenchPart part) {
					// not interesting
				}
				public void partActivated(IWorkbenchPart part) {
					// not interesting
				}};
		}
		return ;
	}

Delegates to the operation framework action handler.
	public void update() {
		if ( != null) {
		}
	}

Delegates to the operation framework action handler.
	public String getDescription() {
		if ( != null) {
else {
			return null;
		}
	}

Delegates to the operation framework action handler.
	public String getText() {
		if ( != null) {
			return .getText();
else {
			return null;
		}
	}

Delegates to the operation framework action handler.
	public String getToolTipText() {
		if ( != null) {
else {
			return null;
		}
	}

Delegates to the operation framework action handler.
	public boolean isEnabled() {
		if ( != null) {
else {
			return false;
		}
	}

Delegates to the operation framework action handler.
	public boolean isHandled() {
		if ( != null) {
else {
			return false;
		}
	}

Delegates to the operation framework action handler.
	public void run() {
		if ( != null) {
		}
	}

Delegates to the operation framework action handler.
	public void runWithEvent(Event event) {
		if ( != null) {
		}
	}

Delegates to the operation framework action handler.
	public void setChecked(boolean checked) {
		if ( != null) {
		}
	}

Delegates to the operation framework action handler.
	public void setDescription(String text) {
		if ( != null) {
		}
	}

Delegates to the operation framework action handler.
	public void setEnabled(boolean enabled) {
		if ( != null) {
		}
	}

Delegates to the operation framework action handler.
	public void setText(String text) {
		if ( != null) {
		}
	}

Delegates to the operation framework action handler.
	public void setToolTipText(String toolTipText) {
		if ( != null) {
		}
	}

Interface of an object that provides private access to the action wrapper that owns me.

Author(s):
Christian W. Damus (cdamus)
	static interface OwnerAccess<T extends Action> {
Fires a property change event on behalf of the owner action wrapper.

Parameters:
property the property to fire
oldValue the property's old value
newValue the property's new value
		void firePropertyChange(String propertyObject oldValueObject newValue);

Creates an operation history action handler of the appropriate undo or redo variety, to which I will delegate.

Parameters:
site the site for the action handler
context the action handler's undo context
Returns:
the new action handler
	}
New to GrepCode? Check out our FAQ X