/*******************************************************************************
* Copyright (c) 2013, 2015 Obeo.
* 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:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.emf.compare.diagram.internal.factories.extensions;
import org.eclipse.emf.compare.AttributeChange;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.DifferenceSource;
import org.eclipse.emf.compare.diagram.internal.extensions.ExtensionsFactory;
import org.eclipse.emf.compare.diagram.internal.extensions.Hide;
import org.eclipse.emf.compare.diagram.internal.factories.AbstractDiagramChangeFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.View;
/**
* Factory of hide changes.
*
* @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a>
*/
public class HideFactory extends AbstractDiagramChangeFactory {
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.compare.internal.postprocessor.factories.AbstractChangeFactory#getExtensionKind()
*/
@Override
public Class<? extends Diff> getExtensionKind() {
return Hide.class;
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.compare.internal.postprocessor.factories.AbstractChangeFactory#createExtension()
*/
@Override
public Hide createExtension() {
return ExtensionsFactory.eINSTANCE.createHide();
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.compare.internal.postprocessor.factories.AbstractChangeFactory#setRefiningChanges(org.eclipse.emf.compare.diagram.internal.extensions.DiagramDiff,
* org.eclipse.emf.compare.DifferenceKind, org.eclipse.emf.compare.Diff)
*/
@Override
public void setRefiningChanges(Diff extension, DifferenceKind extensionKind, Diff refiningDiff) {
if (refiningDiff.getSource() == extension.getSource()) {
extension.getRefinedBy().add(refiningDiff);
}
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.compare.internal.postprocessor.factories.AbstractChangeFactory#isRelatedToAnExtensionChange(org.eclipse.emf.compare.AttributeChange)
*/
@Override
protected boolean isRelatedToAnExtensionChange(AttributeChange input) {
if (input.getAttribute().equals(NotationPackage.eINSTANCE.getView_Visible())) {
final EObject left = input.getMatch().getLeft();
if (left instanceof View) {
final View leftView = (View)left;
final boolean cond1 = !leftView.isVisible() && input.getSource() != DifferenceSource.RIGHT;
final boolean cond2 = leftView.isVisible() && input.getSource() == DifferenceSource.RIGHT;
return cond1 || cond2;
}
}
return false;
}
}