blob: ae15a2c8508805bb83382c383028a9fcb0a94a09 [file] [log] [blame]
//------------------------------------------------------------------------------
// Copyright (c) 2005, 2007 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.diagramming.base.parts;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Path;
import org.eclipse.epf.diagram.core.part.DiagramEditorInput;
import org.eclipse.epf.library.LibraryService;
import org.eclipse.epf.library.edit.util.Suppression;
import org.eclipse.epf.uma.Activity;
import org.eclipse.epf.uma.CapabilityPattern;
import org.eclipse.epf.uma.MethodElement;
import org.eclipse.ui.IElementFactory;
import org.eclipse.ui.IMemento;
/**
* Factory for saving and restoring a {@link DiagramFileEditorInput}.
* The stored representation of a {@link DiagramFileEditorInput} remembers
* the full path of the file and {@link CapabilityPattern} or {@link Activity}'s
* GUID.The workbench will automatically create instances of this class as required.
* It is not intended to be instantiated or subclassed by the client.
* </p>
* @author Shashidhar Kannoori
* @since 1.2
*/
public class DiagramFileEditorInputFactory implements IElementFactory {
/**
* Factory id. The workbench plug-in registers a factory by this name
* with the "org.eclipse.ui.elementFactories" extension point.
*/
private static final String ID_FACTORY = "org.eclipse.epf.diagramming.base.parts.DiagramFileEditorInputFactory"; //$NON-NLS-1$
/**
* Tag for the IFile.fullPath of the file resource.
*/
private static final String TAG_PATH = "path"; //$NON-NLS-1$
/**
* Tag for uma GUID
*
*/
private static final String TAG_GUID = "guid"; //$NON-NLS-1$
/**
*
*/
public DiagramFileEditorInputFactory() {
// TODO Auto-generated constructor stub
}
/* (non-Javadoc)
* @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento)
*/
public IAdaptable createElement(IMemento memento) {
String fileName = memento.getString(TAG_PATH);
if (fileName == null) {
return null;
}
String guid = memento.getString(TAG_GUID);
Suppression suppression = null;
MethodElement element = LibraryService.getInstance().getCurrentLibraryManager().getMethodElement(guid);
if(element instanceof Activity){
suppression = Suppression.getSuppression((org.eclipse.epf.uma.Process)((Activity)element).eContainer());
}
DiagramEditorInput input = new org.eclipse.epf.diagram.core.part.DiagramEditorInput(
element, suppression);
// Get a handle to the IFile...which can be a handle
// to a resource that does not exist in workspace
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(
new Path(fileName));
if (file != null) {
return new DiagramFileEditorInput(file,input );
} else {
return null;
}
}
/**
* Returns the element factory id for this class.
*
* @return the element factory id
*/
public static String getFactoryId() {
return ID_FACTORY;
}
/**
* Saves the state of the given file editor input into the given memento.
*
* @param memento the storage area for element state
* @param input the file editor input
*/
public static void saveState(IMemento memento, DiagramFileEditorInput input) {
IFile file = input.getFile();
memento.putString(TAG_PATH, file.getFullPath().toString());
memento.putString(TAG_GUID, input.getDiagramEditorInput().getMethodElement().getGuid());
}
}