| /** |
| * |
| */ |
| package org.eclipse.epf.diagramming.base.actions; |
| |
| import java.util.ArrayList; |
| |
| import org.eclipse.emf.ecore.EModelElement; |
| import org.eclipse.epf.diagram.core.DiagramCoreResources; |
| import org.eclipse.epf.diagram.core.bridge.BridgeHelper; |
| import org.eclipse.epf.diagram.core.bridge.NodeAdapter; |
| import org.eclipse.epf.diagram.core.services.DiagramHelper; |
| import org.eclipse.epf.diagram.core.services.DiagramManager; |
| import org.eclipse.epf.diagramming.edit.parts.ActivityEditPart; |
| import org.eclipse.epf.library.edit.util.TngUtil; |
| import org.eclipse.epf.uma.BreakdownElement; |
| import org.eclipse.epf.uma.MethodElement; |
| import org.eclipse.epf.uma.VariabilityElement; |
| import org.eclipse.gef.EditPart; |
| import org.eclipse.gef.GraphicalViewer; |
| import org.eclipse.gef.commands.Command; |
| 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; |
| |
| /** |
| * @author skannoor |
| * |
| */ |
| public class RefreshFromBaseAction implements IObjectActionDelegate { |
| |
| private ActivityEditPart editPart; |
| /** |
| * |
| */ |
| public RefreshFromBaseAction() { |
| // 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 |
| refreshFromBaseCommand.execute(); |
| } |
| |
| /* (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); |
| |
| } |
| }else{ |
| action.setEnabled(false); |
| } |
| } |
| |
| /** |
| * Refresh base from previous graphical editor code. |
| * TODO: handle consumer (set) |
| * |
| */ |
| private Command refreshFromBaseCommand = new Command(DiagramCoreResources.AbstractDiagramEditorrefreshfrombase) { //$NON-NLS-1$ |
| private ArrayList oldContent = new ArrayList(); |
| |
| public void execute() { |
| Diagram diagram = (Diagram) editPart.getModel(); |
| |
| EditPart parent = editPart.getParent(); |
| // back up old diagram content |
| // |
| oldContent.clear(); |
| oldContent.addAll(diagram.getPersistedChildren()); |
| |
| boolean refreshed = DiagramHelper.refreshFromBase(diagram); |
| if(!refreshed) return; |
| |
| if (editPart.isActive()) { |
| editPart.deactivate(); |
| } |
| //diagram.removeConsumer(this); |
| //createEditPart(); |
| editPart = (ActivityEditPart)EditPartService.getInstance().createGraphicEditPart(diagram); |
| editPart.setParent(parent); |
| parent.getViewer().setContents(editPart); |
| } |
| |
| public void undo() { |
| Diagram diagram = (Diagram) editPart.getModel(); |
| diagram.getChildren().clear(); |
| diagram.getChildren().addAll(oldContent); |
| if (editPart.isActive()) { |
| editPart.deactivate(); |
| } |
| //diagram.removeConsumer(this); |
| editPart = (ActivityEditPart)EditPartService.getInstance().createGraphicEditPart(diagram); |
| getGraphicalViewer().setContents(editPart); |
| } |
| }; |
| |
| private GraphicalViewer getGraphicalViewer(){ |
| return (GraphicalViewer)editPart.getRoot().getViewer(); |
| } |
| } |