| //------------------------------------------------------------------------------ |
| // Copyright (c) 2005, 2006 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 Corporation - initial implementation |
| //------------------------------------------------------------------------------ |
| package org.eclipse.epf.authoring.gef.util; |
| |
| import java.util.ArrayList; |
| import java.util.Collection; |
| import java.util.Iterator; |
| import java.util.List; |
| |
| import org.eclipse.emf.common.command.Command; |
| import org.eclipse.epf.authoring.ui.util.UIHelper; |
| import org.eclipse.epf.library.edit.ICommandListener; |
| import org.eclipse.epf.library.edit.process.command.VaryActivityCommand; |
| |
| /** |
| * Provides instructure to listens to actions like LocalContribution, Local Replace |
| * in WorkBreakdown Structure. Loads at time of plugin load. |
| * @see VaryActivityCommand |
| * |
| * @author Shashidhar Kannoori |
| * @author Shilpa Toraskar |
| * @since 1.0 |
| */ |
| public final class DiagramEditorUtil { |
| |
| |
| private static DiagramEditorUtil instance = null; |
| |
| private List commandListeners; |
| |
| private DiagramEditorUtil() { |
| } |
| |
| public static DiagramEditorUtil getInstance() { |
| if (instance == null) { |
| synchronized (DiagramEditorUtil.class) { |
| if (instance == null) { |
| instance = new DiagramEditorUtil(); |
| } |
| } |
| } |
| return instance; |
| } |
| public List getVaryCommandListeners() { |
| if (commandListeners == null) { |
| commandListeners = new ArrayList(); |
| } |
| |
| commandListeners.add(new ICommandListener() { |
| |
| public void notifyExecuted(Command command) { |
| // get contributor/replacer of the activity |
| // |
| Object wrapper = ((VaryActivityCommand)command).getWrapper(); |
| UIHelper.closeDiagramEditors(wrapper, new ArrayList()); |
| UIHelper.refreshOpenDiagramEditorsOfParent(wrapper, new ArrayList()); |
| } |
| |
| public Class getCommandType() { |
| return VaryActivityCommand.class; |
| } |
| |
| public void preUndo(Command command) { |
| // get old contributor/replacer of the activity |
| // |
| Collection list = ((VaryActivityCommand)command).getResult(); |
| |
| List listx = new ArrayList(); |
| for(Iterator iterator = list.iterator(); iterator.hasNext();){ |
| Object object = iterator.next(); |
| UIHelper.closeDiagramEditors(object, listx); |
| UIHelper.refreshOpenDiagramEditorsOfParent(object, listx); |
| listx.clear(); |
| } |
| |
| } |
| |
| public void preExecute(Command command) { |
| } |
| }); |
| |
| return commandListeners; |
| } |
| } |