blob: c5e476c51cc019dcdaa6c7ec4d3c616b7c9f2d7c [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
//------------------------------------------------------------------------------
/*
* 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.diagramming.part;
import org.eclipse.epf.diagramming.base.parts.DiagramFileEditorInput;
import org.eclipse.epf.uma.MethodElement;
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.DocumentProviderRegistry;
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument;
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocumentProvider;
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.MEditingDomainElement;
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.DocumentProviderRegistry.IDocumentProviderSelector;
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditorMatchingStrategy;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.PartInitException;
/**
* @generated
*/
public class UMLMatchingStrategy extends DiagramDocumentEditorMatchingStrategy {
/*
* (non-Javadoc)
* @see org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditorMatchingStrategy#matches(org.eclipse.ui.IEditorReference, org.eclipse.ui.IEditorInput)
* @custom
*/
public boolean matches(IEditorReference editorRef, IEditorInput input) {
// TODO Auto-generated method stub
//return super.matches(editorRef, input);
IEditorInput existingEditorInput;
IEditorPart editor = editorRef.getEditor(false);
try {
existingEditorInput = editorRef.getEditorInput();
} catch (PartInitException e) {
return false;
}
// If the ExistingEditorInput is same as the passed input,
// return true
if (existingEditorInput.equals(input))
return true;
else if (!(input instanceof MEditingDomainElement)
&& (editor instanceof DiagramDocumentEditor)) {
// If the input isn't an instanceof MEditingDomainElement, and the editor is instanceof DiagramDocumentEditor
// then don't match it, This indicates that the client shouldn't use this strategy for non-DiagramDocumentEditor.
IDiagramDocumentProvider docProvider = (IDiagramDocumentProvider) DocumentProviderRegistry
.getDefault().getDocumentProvider(input,
new IDocumentProviderSelector() {
public boolean select(String documentType) {
// Only checking of the interface name
return documentType
.equals(IDiagramDocument.class
.getName());
}
});
if (input instanceof DiagramFileEditorInput) {
MethodElement e = ((DiagramFileEditorInput) input)
.getDiagramEditorInput().getMethodElement();
//MethodElement exisitngE =((DiagramFileEditorInput)existingEditorInput).getDiagramEditorInput().getMethodElement();
MethodElement existingE = ((DiagramFileEditorInput) existingEditorInput
.getPersistable()).getDiagramEditorInput()
.getMethodElement();
if (e != existingE)
return false;
}
if (docProvider != null) {
IEditorInput editorInput = docProvider
.createInputWithEditingDomain(input,
((DiagramDocumentEditor) editor)
.getEditingDomain());
return editorInput.equals(existingEditorInput);
}
}
return false;
}
}