| /** |
| * |
| */ |
| package org.eclipse.epf.diagramming.base.actions; |
| |
| import org.eclipse.epf.diagramming.edit.parts.ActivityEditPart; |
| import org.eclipse.gef.EditPart; |
| import org.eclipse.gmf.runtime.diagram.ui.services.editpart.EditPartService; |
| import org.eclipse.gmf.runtime.notation.Diagram; |
| import org.eclipse.jface.action.IAction; |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| import org.eclipse.ui.IObjectActionDelegate; |
| import org.eclipse.ui.IWorkbenchPart; |
| |
| /** |
| * Refresh action refreshes the DiagramEditPart, performs deactivate and activate. |
| * |
| * @author Shashidhar Kannoori |
| * |
| */ |
| public class RefreshAction implements IObjectActionDelegate { |
| |
| private ActivityEditPart editPart; |
| /** |
| * |
| */ |
| public RefreshAction() { |
| // TODO Auto-generated constructor stub |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart) |
| */ |
| public void setActivePart(IAction action, IWorkbenchPart targetPart) { |
| // TODO Auto-generated method stub |
| |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) |
| */ |
| public void run(IAction action) { |
| // TODO Auto-generated method stub |
| Diagram diagram = (Diagram) editPart.getModel(); |
| EditPart parent = editPart.getParent(); |
| if (editPart.isActive()) { |
| editPart.deactivate(); |
| } |
| //TODO: set The consumer. |
| //diagram.removeConsumer(this); |
| //createEditPart(); |
| editPart = (ActivityEditPart)EditPartService.getInstance().createGraphicEditPart(diagram); |
| editPart.setParent(parent); |
| parent.getViewer().setContents(editPart); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) |
| */ |
| public void selectionChanged(IAction action, ISelection selection) { |
| editPart = null; |
| if (selection instanceof IStructuredSelection) { |
| IStructuredSelection structuredSelection = (IStructuredSelection) selection; |
| if (structuredSelection.size() == 1 |
| && structuredSelection.getFirstElement() instanceof ActivityEditPart) { |
| editPart = (ActivityEditPart) structuredSelection |
| .getFirstElement(); |
| } |
| } |
| if(editPart != null){ |
| Diagram diagram = (Diagram)editPart.getModel(); |
| if(diagram != null){ |
| // NodeAdapter adapter= BridgeHelper.getNodeAdapter(diagram.getElement()); |
| // if(((VariabilityElement)adapter.getElement()).getVariabilityBasedOnElement() == null) |
| // action.setEnabled(false); |
| action.setEnabled(true); |
| |
| } |
| }else{ |
| action.setEnabled(false); |
| } |
| |
| } |
| |
| } |